<?php 

	class WS_StudentInformationMod {
		
		private $_DB;
		
		public function __construct() {

			$this->_DB 	= new ConfigDB();

		}
		
		public function gradeConvertion($strGrade) {
			
			$strGrade = escapestring($strGrade);
			
			$strArray = array('1.0', '1', '1.25', '1.50', '1.5', '1.75', '2.0', '2', '2.25', '2.50', '2.5', '2.75', '3.0', '3', '4.0', '4', '5.0', '5', 'INC', 'DRP');

			if (in_array($strGrade, $strArray)) {
				switch($strGrade) {
					case '1.0'	: 
					case '1'  	: 	$equivalence 		= '1.0'; 
							 		$letterEquivalence	= 'A'; 
							 		$description 		= 'Excellent'; 			break;
									
					case '1.25'	: 	$equivalence 		= '1.25'; 
							 		$letterEquivalence	= 'A-'; 
							 		$description 		= 'Superior'; 			break;
					case '1.50'	: 
					case '1.5'  : 	$equivalence 		= '1.50'; 
							 		$letterEquivalence	= 'B+'; 
							 		$description 		= 'Very Satisfactory'; 	break;
									
					case '1.75'  : 	$equivalence 		= '1.75'; 
							 		$letterEquivalence	= 'B'; 
							 		$description 		= 'Very Satisfactory';	break;
									
					case '2.0'	: 
					case '2'  	: 	$equivalence 		= '2.0'; 
							 		$letterEquivalence	= 'B-'; 
							 		$description 		= 'Satisfactory';		break;
									
					case '2.25'	: 	$equivalence 		= '2.25'; 
							 		$letterEquivalence	= 'C+'; 
							 		$description 		= 'Good'; 				break;
					case '2.50'	: 
					case '2.5'  : 	$equivalence 		= '2.50'; 
							 		$letterEquivalence	= 'C'; 
							 		$description 		= 'Average'; 			break;
									
					case '2.75'  : 	$equivalence 		= '2.75'; 
							 		$letterEquivalence	= 'C-'; 
							 		$description 		= 'Fair';				break;
					case '3.0'	: 
					case '3'  	: 	$equivalence 		= '3.0'; 
							 		$letterEquivalence	= 'D'; 
							 		$description 		= 'Passed'; 			break;
					case '4.0'	: 
					case '4'  	: 	$equivalence 		= '4.0'; 
							 		$letterEquivalence	= 'F'; 
							 		$description 		= '<span class="font-red">Failed</span>'; 		break;
					case '5.0'	: 
					case '5'  	: 	$equivalence 		= '5.0'; 
							 		$letterEquivalence	= 'F'; 
							 		$description 		= '<span class="font-red">Failed</span>'; 		break;
									
					case 'INC'  : 	$equivalence 		= '<span class="font-red">INC</span>'; 
							 		$letterEquivalence	= '<span class="font-red">INC</span>'; 
							 		$description 		= '<span class="font-red">Incomplete</span>'; 	break;
									
					case 'DRP'  : 	$equivalence 		= '<span class="font-red">DRP</span>'; 
							 		$letterEquivalence	= '<span class="font-red">DRP</span>'; 
							 		$description 		= '<span class="font-red">Failed</span>'; 		break;
				}
				
				return array('equivalence' => $equivalence, 'letter_equivalence' => $letterEquivalence, 'description' => $description);
				
			}
			else {
				return $this->_DB->selectDB2("SELECT `equivalence`, `letter_equivalence`, `description` FROM `tbl_convertion` WHERE `from_range` <= '" . $strGrade . "' AND `to_range` > '" . $strGrade . "'");
			}
			
		
		}
		
		public function getScheduleDefaultTime($arrDaysSchedules, $strYearActive) {
			
			if ( !empty($arrDaysSchedules) ) {
				$strDaysScheduleFor = "";
				foreach($arrDaysSchedules as $strDaysSchedulesValue) {
					$strDaysScheduleFor .= "'" . escapestring($strDaysSchedulesValue) . "',";
				}
				$strDaysScheduleTrim = trim(rtrim($strDaysScheduleFor, ','));
				
				if ( !empty($strYearActive) ) {
					$whereYear = " AND `year_idFK` = '" . escapestring($strYearActive) . "'";
				}
												
				return $this->_DB->selectDB("SELECT `sched_time_idPK`, `sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_time`, `sched_break` FROM `tbl_sched_time` WHERE `sched_day` IN (" . $strDaysScheduleTrim . ")" . $whereYear);
				
			}
			
		}
		
		public function getScheduleTimeID($strSchedTimeID) {
			
			$strSchedTimeID = escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT `sched_time_idPK`, `sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_time`, `sched_break` FROM `tbl_sched_time` WHERE `sched_time_idPK` = '" . $strSchedTimeID . "'");
				
		}
		
		public function listStudentInformation($strSearch, $pageLimit) {
			
			$strSearch 		= escapestring($strSearch);
			$whereCondition = '';
			
			if ( !empty($strSearch) ) {
				$whereCondition .= " AND (s.`first_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`last_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`email` 		LIKE '%" . $strSearch . "%'
									  OR  s.`stud_no` 	= '" . $strSearch . "') ";
			}

			return $this->_DB->selectDB("SELECT s.`stud_idPK`,
												s.`stud_no`,
												s.`log_user`,
												s.`picture`,
												s.`first_name`,
												s.`last_name`,
												s.`middle_name`,
												s.`birthdate`,
												s.`gender`,
												s.`email`,
												s.`contact_no`,
												s.`address`, 
												s.`guardian`,
												s.`first_reg`,
												s.`course_idFK`,
												c.`course_code`,
												c.`course_desc`,
												s.`is_deleted`,
												s.`is_active`
											FROM `tbl_students` s
											INNER JOIN `tbl_courses` c ON c.`course_idPK` = s.`course_idFK`
											WHERE s.`is_deleted` = 'N'" . $whereCondition . $pageLimit);

		}
		
		public function listStudentInformationValidate($strSearch, $activeYear, $pageLimit) {
			
			$strSearch 		= escapestring($strSearch);
			$activeYear 	= escapestring($activeYear);
			$whereCondition = '';
			
			if ( !empty($strSearch) ) {
				$whereCondition .= " AND (s.`first_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`last_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`email` 		LIKE '%" . $strSearch . "%'
									  OR  s.`stud_no` 	= '" . $strSearch . "') ";
			}

			return $this->_DB->selectDB("SELECT DISTINCT s.`stud_idPK`,
														s.`stud_no`,
														s.`log_user`,
														s.`picture`,
														s.`first_name`,
														s.`last_name`,
														s.`middle_name`,
														s.`birthdate`,
														s.`gender`,
														s.`email`,
														s.`contact_no`,
														s.`address`, 
														s.`guardian`,
														s.`first_reg`,
														s.`course_idFK`,
														c.`course_code`,
														c.`course_desc`,
														s.`is_deleted`,
														s.`is_active`
													FROM `tbl_stud_sem` ss
													INNER JOIN `tbl_students` s ON ss.`stud_idFK` = s.`stud_idPK`
													INNER JOIN `tbl_courses` c ON c.`course_idPK` = ss.`course_idFK`
													WHERE s.`is_deleted` = 'N' AND ss.`is_deleted` = 'N' AND ss.`is_active` = 'N' AND ss.`year_idFK` = '" . $activeYear . "'" . $whereCondition . $pageLimit);

		}
		
		public function getLastStudentID() {

			return $this->_DB->selectDB2("SELECT `stud_idPK` FROM `tbl_students` ORDER BY `stud_idPK` DESC LIMIT 1");

		}
		
		public function getStudentInformation($strID) {
			
			$strID 		= escapestring($strID);

			return $this->_DB->selectDB2("SELECT s.`stud_idPK`,
												 s.`stud_no`,
												 s.`first_name`,
												 s.`last_name`,
												 s.`middle_name`,
												 s.`course_idFK`,
												 s.`picture`,
												 s.`birthdate`,
												 s.`gender`,
												 s.`email`,
												 s.`contact_no`,
												 s.`address`, 
												 s.`guardian`,
												 s.`log_user`,
												 c.`course_code`,
												 c.`course_major`,
												 c.`course_desc`,
												 d.`dept_desc`
											FROM `tbl_students` s
											INNER JOIN `tbl_courses` c ON c.`course_idPK` = s.`course_idFK`
											INNER JOIN `tbl_department` d ON d.`dept_idPK` = c.`dept_idFK`
											WHERE s.`stud_idPK` = '" . $strID . "' LIMIT 1");

		}
		
		public function insertStudentInformation($strArray, $isActive) {

			$stud_no 		= escapestring($strArray['stud_no']);
			$first_name 	= escapestring($strArray['first_name']);
			$last_name 		= escapestring($strArray['last_name']);
			$middle_name 	= escapestring($strArray['middle_name']);
			$birthdate 		= escapestring($strArray['birthdate']);
			$gender 		= escapestring($strArray['gender']);
			$email 			= escapestring($strArray['email']);
			$contact_no 	= escapestring($strArray['contact_no']);
			$address 		= escapestring($strArray['address']);
			$guardian 		= escapestring($strArray['guardian']);
			
			$course_id 		= escapestring($strArray['course_id']);
			
			$log_user 		= escapestring($strArray['log_user']);
			$log_pass 		= escapestring($strArray['log_pass']);
			
			$is_active  = ( $isActivate === true ) ? ", 'Y'" : ", 'N'";
			
			$this->_DB->queryDB("INSERT INTO `tbl_students` (`stud_no`,
															  `first_name`,
															  `last_name`,
															  `middle_name`,
															  `birthdate`,
															  `gender`,
															  `email`,
															  `contact_no`,
															  `address`,
															  `guardian`,
															  `course_idFK`,
															  `log_user`,
															  `log_pass`,
															  `is_active`) VALUES ('" . $stud_no 		. "',
																				  '" . $first_name 		. "',
																				  '" . $last_name 		. "',
																				  '" . $middle_name 	. "',
																				  '" . $birthdate 		. "',
																				  '" . $gender 			. "',
																				  '" . $email 			. "',
																				  '" . $contact_no 		. "',
																				  '" . $address 		. "',
																				  '" . $guardian 		. "',
																				  '" . $course_id		. "',
																				  '" . $log_user 		. "',
																				  '" . md5($log_pass)	. "'
																				   " . $is_active		. ")");
			return mysql_insert_id();
			
		}
		
		public function insertStudentTransferyGrades($strArray, $activeSubjTaken) {
														   
			$stud_id 		= escapestring($strArray['stud_id']);
			$subj_id 		= escapestring($strArray['subj_id']);
			$course_id 		= escapestring($strArray['course_id']);
			$sem_id 		= escapestring($strArray['sem_id']);
			$year_id 		= escapestring($strArray['year_id']);
			$grades 		= escapestring($strArray['grades']);
			$subj_taken 	= escapestring($activeSubjTaken);

			$this->_DB->queryDB("DELETE FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $stud_id . "' AND `subj_idFK` = '" . $subj_id . "' AND `course_idFK` = '" . $course_id . "' AND `sem_idFK` = '" . $sem_id . "'");

			$this->_DB->queryDB("INSERT INTO `tbl_stud_subj_linker` (`stud_idFK`, `subj_idFK`, `course_idFK`, `sem_idFK`, `year_idFK`, `grade`, `stud_sem_active`)
									VALUES ('" . $stud_id . "', '" . $subj_id . "', '" . $course_id . "', '" . $sem_id . "', '" . $year_id . "', '" . $grades . "', '" . $subj_taken . "')");

			return mysql_insert_id();
			
		}
		
		public function insertStudentSemesterActive($studID, $courseID, $activeSubjTaken, $strActiveYear, $isRegularStudent) {
														   
			$studID 			= escapestring($studID);
			$courseID 			= escapestring($courseID);
			$activeSubjTaken 	= escapestring($activeSubjTaken);
			$strActiveYear 		= escapestring($strActiveYear);
			$isRegularStudent 	= escapestring($isRegularStudent);

			$this->_DB->queryDB("DELETE FROM `tbl_stud_sem` WHERE `stud_idFK` = '" . $studID . "' AND `course_idFK` = '" . $courseID . "' AND `year_idFK` = '" . $strActiveYear . "' AND `is_active` = 'N'");

			$this->_DB->queryDB("INSERT INTO `tbl_stud_sem` (`stud_idFK`, `course_idFK`, `sem_linker_idFK`, `year_idFK`, `is_regular`) VALUES ('" . $studID . "', '" . $courseID . "', '" . $activeSubjTaken . "', '" . $strActiveYear . "', '" . $isRegularStudent . "')");

		}
		
		public function updateStudentTransferyGrades($strArray, $strID) {
														   
			$stud_id 		= escapestring($strArray['stud_id']);
			$subj_id 		= escapestring($strArray['subj_id']);
			$course_id 		= escapestring($strArray['course_id']);
			$sem_id 		= escapestring($strArray['sem_id']);
			$year_id 		= escapestring($strArray['year_id']);
			$grades 		= escapestring($strArray['grades']);
			
			$strID 			= escapestring($strID);

			$this->_DB->queryDB("UPDATE `tbl_stud_subj_linker` SET `stud_idFK` 	 = '" . $stud_id 	. "',
																   `subj_idFK` 	 = '" . $subj_id 	. "',
																   `course_idFK` = '" . $course_id 	. "',
																   `sem_idFK` 	 = '" . $sem_id 	. "',
																   `year_idFK` 	 = '" . $year_id 	. "',
																   `grade` 		 = '" . $grades 	. "'
															WHERE  `stud_subj_linker_idPK` = '" . $strID . "'");
			return $strID;
		}
		
		public function updateStudentGrades($strGrades, $strID) {
			
			$grades 		= escapestring($strGrades);
			$strID 			= escapestring($strID);

			$this->_DB->queryDB("UPDATE `tbl_stud_subj_linker` SET `grade`  = '" . $grades 	. "' WHERE `stud_subj_linker_idPK` = '" . $strID . "'");
			return $strID;
		}
		
		public function getStudentSubjectGrades($strStudentID, $strSubjectID, $strCourseID, $strSemesterID) {

			$strStudentID 	= escapestring($strStudentID);
			$strSubjectID 	= escapestring($strSubjectID);
			$strCourseID 	= escapestring($strCourseID);
			$strSemesterID 	= escapestring($strSemesterID);

			return $this->_DB->selectDB2("SELECT 	 tssl.`stud_subj_linker_idPK`, tssl.`subj_idFK`, tssl.`grade`, tssl.`grade_remarks`
										  FROM 	 	 `tbl_stud_subj_linker` tssl
										  WHERE		 tssl.`stud_idFK` = '" . $strStudentID . "' AND tssl.`subj_idFK` = '" . $strSubjectID . "' AND tssl.`course_idFK` = '" . $strCourseID . "' AND tssl.`sem_idFK` = '" . $strSemesterID . "' ORDER BY tssl.`stud_subj_linker_idPK` DESC LIMIT 1");
			
		}
		
		public function getStudentSubjectAlreadyTaken($strStudentID, $strCourseID) {

			$strStudentID 	= escapestring($strStudentID);
			$strCourseID 	= escapestring($strCourseID);

			return $this->_DB->selectDB("SELECT tssl.`subj_idFK`
										 FROM 	`tbl_stud_subj_linker` tssl
										 WHERE tssl.`stud_idFK` = '" . $strStudentID . "' AND tssl.`course_idFK` = '" . $strCourseID . "' AND tssl.`grade` IN ('INC', 'DRP', '')");
			
		}
		
		public function getStudentSubjectGradesList($strStudentID, $strCourseID, $strActiveSemester) {

			$strStudentID 	= escapestring($strStudentID);
			$strCourseID 	= escapestring($strCourseID);
			$strActiveSemester 	= escapestring($strActiveSemester);
			
			if (!empty($strActiveSemester)) {
				$whereActive = " AND tssl.`sem_idFK` 	= '" . $strActiveSemester . "'";
			}
			
			return $this->_DB->selectDB("SELECT DISTINCT tssl.`stud_subj_linker_idPK`,
												tssl.`sem_idFK`,
												s.`subj_idPK`,
												s.`subj_desc`,
												s.`subj_code`,
												s.`total_units`,
												tssl.`grade`,
												tssl.`grade_remarks`
										 FROM 	`tbl_stud_subj_linker` tssl
											INNER JOIN `tbl_subject` s ON s.`subj_idPK` = tssl.`subj_idFK`
										 WHERE tssl.`stud_idFK` 	= '" . $strStudentID . "'
											AND tssl.`course_idFK` 	= '" . $strCourseID . "'
											" . $whereActive . "
											AND tssl.`is_deleted` = 'N'
											ORDER BY s.`subj_idPK` ASC");
			
		}
		
		public function getStudentSubjectListSemester($strStudentID, $strCourseID, $strActiveSemester) {

			$strStudentID 	= escapestring($strStudentID);
			$strCourseID 	= escapestring($strCourseID);
			$strActiveSemester 	= escapestring($strActiveSemester);
			
			return $this->_DB->selectDB("SELECT DISTINCT tssl.`stud_subj_linker_idPK`,
														tssl.`sem_idFK`,
														tssl.`subj_idFK`,
														tssl.`grade`,
														tssl.`grade_remarks`,
														s.`total_hrs`,
														s.`subj_desc`,
														s.`subj_code`
												 FROM 	`tbl_stud_subj_linker` tssl
												 INNER JOIN `tbl_subject` s
												 	ON s.`subj_idPK` = tssl.`subj_idFK`
												 WHERE tssl.`stud_idFK` 	= '" . $strStudentID . "'
													AND tssl.`course_idFK` 	= '" . $strCourseID . "'
													AND tssl.`stud_sem_active` 	= '" . $strActiveSemester . "'
													AND tssl.`is_deleted` = 'N'");
			
		}
		
		public function getStudentReqesutSubjectDelete($strStudID, $strStudentSemActiveID) {

			$strStudID 				= escapestring($strStudID);
			$strStudentSemActiveID 	= escapestring($strStudentSemActiveID);
			
			return $this->_DB->selectDB2("SELECT `is_accepted` FROM `tbl_stud_drop_subj_irreg`  WHERE `stud_subj_linker_idPK` = '" . $strStudentSemActiveID . "' AND `stud_idFK` = '" . $strStudID . "' AND `is_deleted` = 'N'");
			
		}
		
		public function deleteSubjEnrolled($strStudSubjLinkerID) {
			
			$strStudSubjLinkerID = escapestring($strStudSubjLinkerID);
			
			$res 	 = $this->_DB->selectDB2("SELECT `stud_idFK`, `course_idFK`, `year_idFK`, `stud_sem_active` FROM `tbl_stud_subj_linker` WHERE `stud_subj_linker_idPK` = '" . $strStudSubjLinkerID . "'");
			
			$this->_DB->queryDB("DELETE FROM `tbl_stud_subj_linker` WHERE `stud_subj_linker_idPK` = '" . $strStudSubjLinkerID . "'");
			
			return $res;
			
		}
		
		public function deleteSubjEnrolledGrades($strStudSubjLinkerID) {
			
			$strStudSubjLinkerID = escapestring($strStudSubjLinkerID);
			
			$resGrades = $this->_DB->selectDB2("SELECT tssl.`stud_idFK`,
													   tssl.`course_idFK`,
													   tssl.`stud_sem_active`,
													   tssl.`year_idFK`,
													   tssl.`subj_idFK`,
													   tssl.`stud_subj_linker_idPK`,
													   s.`stud_no`,
													   s.`first_name`,
													   s.`last_name`,
													   s.`middle_name`,
													   s.`email`
												FROM `tbl_stud_subj_linker` tssl
												INNER JOIN `tbl_students` s ON s.`stud_idPK` = tssl.`stud_idFK` AND s.`is_deleted` = 'N' AND s.`is_active` = 'Y'
												WHERE tssl.`stud_subj_linker_idPK` = '" . $strStudSubjLinkerID . "'");
			
			$stud_no		= $resGrades['stud_no'];
			$first_name		= $resGrades['first_name'];
			$last_name		= $resGrades['last_name'];
			$middle_name	= $resGrades['middle_name'];
			$email			= $resGrades['email'];
			
			$this->_DB->queryDB("INSERT INTO `tbl_stud_drop_subj_irreg` (`stud_idFK`, `course_idFK`, `sem_linker_idFK`, `year_idFK`, `subj_idFK`, `stud_subj_linker_idPK`) VALUES ('" . $resGrades['stud_idFK'] . "', '" . $resGrades['course_idFK'] . "', '" . $resGrades['stud_sem_active'] . "', '" . $resGrades['year_idFK'] . "', '" . $resGrades['subj_idFK'] . "', '" . $resGrades['stud_subj_linker_idPK'] . "')");
			$stud_drop_subj_irreg_id = mysql_insert_id();
			
			$this->_DB->queryDB("INSERT INTO `tbl_stud_request` (`stud_no`, `first_name`, `last_name`, `middle_name`, `email`, `request_type`, `table_request`, `table_id`) VALUES ('" . $stud_no	 . "', '" . $first_name . "', '" . $last_name. "', '" . $middle_name . "', '" . $email . "', 'irreg_subj', 'tbl_stud_drop_subj_irreg', '" . $stud_drop_subj_irreg_id . "')");
			
		}
		
		public function updateStudDropSubjIrreg($strStatus, $strTableRequest, $strTableID) {
			
			$strStatus 			= escapestring($strStatus);
			$strTableRequest 	= escapestring($strTableRequest);
			$strTableID 		= escapestring($strTableID);
			
			$this->_DB->queryDB("DELETE FROM  `tbl_stud_request` WHERE `table_request` = '" . $strTableRequest . "' AND  `table_id` = '" . $strTableID . "'");
			$this->_DB->queryDB("UPDATE `tbl_stud_drop_subj_irreg` SET `is_accepted` = '" . $strStatus . "' WHERE `sdsi_idPK` = '" . $strTableID . "'");
			
		}
		
		public function deleteStudSemEnrolled($strStudID, $strCourseID, $strYearID, $strStudSemActiveID) {
			
			$strStudID 			= escapestring($strStudID);
			$strCourseID 		= escapestring($strCourseID);
			$strYearID 			= escapestring($strYearID);
			$strStudSemActiveID = escapestring($strStudSemActiveID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_stud_sem` WHERE `stud_idFK` = '" . $strStudID . "' AND `course_idFK` = '" . $strCourseID . "' AND `sem_linker_idFK` = '" . $strStudSemActiveID . "' AND `year_idFK` = '" . $strYearID . "'");
			
		}
		
		public function deleteStudSecEnrolled($strStudSemID, $strCourseID, $strStudSemActiveID) {
			
			$strStudSemID 		= escapestring($strStudSemID);
			$strCourseID 		= escapestring($strCourseID);
			$strStudSemActiveID = escapestring($strStudSemActiveID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_stud_sec` WHERE `stud_sem_idFK` = '" . $strStudSemID . "' AND `course_idFK` = '" . $strCourseID . "' AND `sem_linker_idFK` = '" . $strStudSemActiveID . "'");
			
		}
		
		public function getSubjEnrolled($strStudID, $strCourseID, $strYearID, $strStudSemActiveID) {
			
			$strStudID 			= escapestring($strStudID);
			$strCourseID 		= escapestring($strCourseID);
			$strYearID 			= escapestring($strYearID);
			$strStudSemActiveID = escapestring($strStudSemActiveID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS tssl FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $strStudID . "' AND `course_idFK` = '" . $strCourseID . "' AND `year_idFK` = '" . $strYearID . "' AND `stud_sem_active` = '" . $strStudSemActiveID . "'");
			
		}
		
		public function getSubjEnrolledValue($strStudID, $strCourseID, $strYearID, $strStudSemActiveID) {
			
			$strStudID 			= escapestring($strStudID);
			$strCourseID 		= escapestring($strCourseID);
			$strYearID 			= escapestring($strYearID);
			$strStudSemActiveID = escapestring($strStudSemActiveID);
			
			return $this->_DB->selectDB2("SELECT `stud_sem_idPK` FROM `tbl_stud_sem` WHERE `stud_idFK` = '" . $strStudID . "' AND `course_idFK` = '" . $strCourseID . "' AND `year_idFK` = '" . $strYearID . "' AND `sem_linker_idFK` = '" . $strStudSemActiveID . "'");
			
		}
		
		public function getStudentSubjectTakenList($strStudentID, $strCourseID, $strActiveSemester) {

			$strStudentID 	= escapestring($strStudentID);
			$strCourseID 	= escapestring($strCourseID);
			$strActiveSemester 	= escapestring($strActiveSemester);
							
			return $this->_DB->selectDB("SELECT DISTINCT tssl.`stud_subj_linker_idPK`,
												tssl.`sem_idFK`,
												s.`subj_idPK`,
												s.`total_units`,
												s.`subj_desc`,
												s.`subj_code`,
												s.`total_units`,
												s.`total_hrs`,
												tssl.`grade`,
												tssl.`grade_remarks`,
												tssl.`stud_sem_active`
										 FROM 	`tbl_stud_subj_linker` tssl
											INNER JOIN `tbl_subject` s ON s.`subj_idPK` = tssl.`subj_idFK`
										 WHERE tssl.`stud_idFK` 		= '" . $strStudentID . "'
											AND tssl.`course_idFK` 		= '" . $strCourseID . "'
											AND tssl.`stud_sem_active` 	= '" . $strActiveSemester . "'
											AND tssl.`is_deleted`		= 'N'	
											AND s.`is_deleted`			= 'N'	
											ORDER BY s.`subj_idPK` ASC");
			
		}
		
		public function getStudentSubjectTakenListReg($strStudentID, $strCourseID, $strActiveSemester) {

			$strStudentID 	= escapestring($strStudentID);
			$strCourseID 	= escapestring($strCourseID);
			$strActiveSemester 	= escapestring($strActiveSemester);
							
			return $this->_DB->selectDB("SELECT DISTINCT tssl.`stud_subj_linker_idPK`,
												tssl.`sem_idFK`,
												s.`subj_idPK`,
												s.`total_units`,
												s.`subj_desc`,
												s.`subj_code`,
												s.`total_units`,
												s.`total_hrs`,
												tssl.`grade`,
												tssl.`grade_remarks`,
												tssl.`stud_sem_active`
										 FROM 	`tbl_stud_subj_linker` tssl
											INNER JOIN `tbl_subject` s ON s.`subj_idPK` = tssl.`subj_idFK`
										 WHERE tssl.`stud_idFK` 		= '" . $strStudentID . "'
											AND tssl.`course_idFK` 		= '" . $strCourseID . "'
											AND tssl.`stud_sem_active` 	!= 0
											AND tssl.`is_deleted`		= 'N'	
											AND s.`is_deleted`			= 'N'	
											ORDER BY s.`subj_idPK` ASC");
			
		}
		
		public function ActivateStudentSemester($strActiveSemesterID) {
			
			$strActiveSemesterID = escapestring($strActiveSemesterID);
			
			$this->_DB->queryDB("UPDATE `tbl_stud_sem` SET `is_active` = 'Y' WHERE `stud_sem_idPK` = '" . $strActiveSemesterID . "'");
			
		}
		
		public function getStudentSubjectTakenListValidate($strStudentID, $strCourseID, $strActiveSemester) {

			$strStudentID 		= escapestring($strStudentID);
			$strCourseID 		= escapestring($strCourseID);
			$strActiveSemester 	= escapestring($strActiveSemester);
			return $this->_DB->selectDB("SELECT DISTINCT tssl.`stud_subj_linker_idPK`,
												tssl.`sem_idFK`,
												s.`subj_idPK`,
												s.`total_units`,
												s.`subj_desc`,
												s.`subj_code`,
												s.`total_units`,
												tssl.`grade`,
												tssl.`grade_remarks`
										 FROM 	`tbl_stud_sem` ssem
										 	INNER JOIN `tbl_stud_subj_linker` tssl ON tssl.`stud_sem_active` = ssem.`sem_linker_idFK`
											INNER JOIN `tbl_subject` s ON s.`subj_idPK` = tssl.`subj_idFK`
										 WHERE ssem.`stud_idFK` 		= '" . $strStudentID . "'
											AND tssl.`course_idFK` 		= '" . $strCourseID . "'
											AND ssem.`sem_linker_idFK` 	= '" . $strActiveSemester . "'
											AND tssl.`is_deleted`		= 'N'	
											AND s.`is_deleted`			= 'N'
											AND ssem.`is_deleted`		= 'N'
											AND ssem.`is_active`		= 'Y'
											ORDER BY s.`subj_idPK` ASC");
			
		}
		
		public function getStudSubjUntakenPerSemester($strSubjTaken, $strSemTaken, $semLinkerID) {
			
			$strSubjTaken 	= escapestring($strSubjTaken);
			$strSemTaken 	= escapestring($strSemTaken);
			
			if (!empty($semLinkerID)) {
				$strSemTaken = $strSemTaken . ',' . escapestring($semLinkerID);
			}
			
			return $this->_DB->selectDB("SELECT s.`subj_idPK`, s.`subj_desc`, s.`subj_code`, s.`subj_code`, s.`co_req`, s.`pre_req`, s.`total_units`,  s.`sem_linker_idFK` FROM `tbl_subject` s WHERE s.`sem_linker_idFK` IN (" . $strSemTaken . ") AND s.`subj_idPK` NOT IN (" . $strSubjTaken . ") AND s.`is_deleted` = 'N'");
			
		}
			
		public function manualSubjRequisite() {
			
			$return = $this->_DB->selectDB("SELECT s.`subj_idPK`, s.`sem_linker_idFK`, s.`co_req`, s.`pre_req`, sl.`course_idFK` FROM `tbl_subject` s INNER JOIN `tbl_sem_linker` sl ON sl.`sem_linker_idPK` = s.`sem_linker_idFK`");
			
			foreach($return as $value) {
				if (!empty($value['co_req'])) {
					 $co_req = explode('-', $value['co_req']);
					 if(!empty($co_req)) {
						 foreach($co_req as $co_reqvalue) {
							$this->_DB->queryDB("INSERT INTO `tbl_requisite` (`subj_idFK`, `course_idFK`, `sem_linker_idFK`, `co_req`) VALUES ('" . $value['subj_idPK'] . "', '" . $value['course_idFK'] . "', '" . $value['sem_linker_idFK'] . "', '" . $co_reqvalue . "')");
						 }
					 }
				}
				
				if (!empty($value['pre_req'])) {
					$pre_req =  explode('-', $value['pre_req']);
					 if(!empty($pre_req)) {
						 foreach($pre_req as $pre_reqvalue) {
							$this->_DB->queryDB("INSERT INTO `tbl_requisite` (`subj_idFK`, `course_idFK`, `sem_linker_idFK`, `pre_req`) VALUES ('" . $value['subj_idPK'] . "', '" . $value['course_idFK'] . "', '" . $value['sem_linker_idFK'] . "', '" . $pre_reqvalue . "')");
						 }
					 }
				}
				
			}
			
		}
		
		public function getSemesterSubjectList($strSemLinkerID) {
			
			$strSemLinkerID	= escapestring($strSemLinkerID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count` FROM `tbl_subject` WHERE `sem_linker_idFK` = '" . $strSemLinkerID . "' AND `is_deleted` = 'N'");
			
		}
		
		public function getPassFailedEnrollment($studID) {
			
			$studID 	= escapestring($studID);
			
			return $this->_DB->selectDB2("SELECT `stud_sem_idPK`, `sem_linker_idFK`, `is_active`, `is_regular` FROM `tbl_stud_sem` WHERE `stud_idFK` = '" . $studID . "' ORDER BY `stud_sem_idPK` DESC LIMIT 1");
			
		}
		
		public function activateStudent($studID) {
			
			$studID 	= escapestring($studID);
			
			$this->_DB->queryDB("UPDATE `tbl_students` SET `is_active` = 'Y' WHERE `stud_idPK` = '" . $studID . "'");
			
		}
		
		public function getPassFailedEnrollmentSubject($studID, $semSubjLinkerID) {
			
			$studID 			= escapestring($studID);
			$semSubjLinkerID 	= escapestring($semSubjLinkerID);
			//return $this->_DB->selectDB("SELECT `grade` FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $studID . "' AND `sem_idFK` IN (" . $semSubjLinkerID . ")");
			return $this->_DB->selectDB("SELECT
												  `grade`
												FROM `tbl_stud_subj_linker`
												WHERE `stud_idFK` = '" . $studID . "'
													AND `sem_idFK` IN(SELECT DISTINCT
																		`sem_idFK`
																	  FROM `tbl_stud_subj_linker`
																	  WHERE `stud_idFK` = '" . $studID . "'
																		  AND `stud_sem_active` = '" . $semSubjLinkerID . "')
													AND `stud_sem_active` = '" . $semSubjLinkerID . "'");
			
		}
		
		public function getIrregularSemesterListSection($semSubjLinkerID) {
			
			$semSubjLinkerID = escapestring($semSubjLinkerID);
			
			return $this->_DB->selectDB2("SELECT `section_idPK`
										 FROM 	`tbl_section`
										 WHERE 	`sem_idFK` = '" . $semSubjLinkerID . "'
										 ORDER BY RAND() LIMIT 1");
			
		}
		
		public function getIrregularSemesterList($studID, $semSubjLinkerID) {
			
			$studID 			= escapestring($studID);
			$semSubjLinkerID 	= escapestring($semSubjLinkerID);
			
			return $this->_DB->selectDB("SELECT DISTINCT `sem_idFK` FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $studID . "' AND `stud_sem_active` = '" . $semSubjLinkerID . "'");
			
		}
		
		public function updateStudentSection($strSectionID, $strStudSecSemID, $strCourseID, $strSemLinkerID) {
			
			$strSectionID 		= escapestring($strSectionID);
			$strStudSecSemID 	= escapestring($strStudSecSemID);
			$strCourseID 		= escapestring($strCourseID);
			$strSemLinkerID 	= escapestring($strSemLinkerID);
			
			$this->_DB->queryDB("UPDATE `tbl_stud_sec` SET `section_idFK` = '" . $strSectionID . "' WHERE `stud_sem_idFK` = '" . $strStudSecSemID . "' AND `course_idFK` = '" . $strCourseID . "' AND `sem_linker_idFK` = '" . $strSemLinkerID . "'");
			
		}
			
		public function getStudSubjEnrollID($strSubjEnroll, $strCourseID = '') {
				
			$strCourseID = escapestring($strCourseID);
			
			if ( !empty($strSubjEnroll) ) {
				$strSubjEnr = "";
				foreach($strSubjEnroll as $strSubjEnrollValue) {
					$strSubjEnr .= "'" . escapestring($strSubjEnrollValue) . "',";
				}
				$strSubjEnrVal = trim(rtrim($strSubjEnr, ','));
											
				$result = $this->_DB->selectDB("SELECT s.`subj_idPK`, s.`sem_linker_idFK`, s.`total_units`
												FROM	`tbl_subject` s
												INNER JOIN `tbl_sem_linker` sl ON s.`sem_linker_idFK` = sl.`sem_linker_idPK` 
												WHERE	s.`subj_code` IN (" . $strSubjEnrVal . ") AND sl.`course_idFK` = '" . $strCourseID . "' AND s.`is_deleted` = 'N'");
				return $result;
			}
		}
			
		public function getStudSubjEnrollIDSemester($strSubjEnroll, $strCourseID = '') {
				
			$strCourseID = escapestring($strCourseID);
			
			if ( !empty($strSubjEnroll) ) {
				$strSubjEnr = "";
				foreach($strSubjEnroll as $strSubjEnrollValue) {
					$strSubjEnr .= "'" . escapestring($strSubjEnrollValue) . "',";
				}
				$strSubjEnrVal = trim(rtrim($strSubjEnr, ','));
											
				$result = $this->_DB->selectDB("SELECT DISTINCT `sem_linker_idFK`
												FROM	`tbl_subject` s
												INNER JOIN `tbl_sem_linker` sl ON s.`sem_linker_idFK` = sl.`sem_linker_idPK` 
												WHERE	s.`subj_code` IN (" . $strSubjEnrVal . ") AND sl.`course_idFK` = '" . $strCourseID . "' AND s.`is_deleted` = 'N'");
				return $result;
			}
		}
		
		
			
		public function getStudSubjEnrollIDViaID($strSubjEnroll, $strCourseID = '') {
				
			$strCourseID = escapestring($strCourseID);
			
			if ( !empty($strSubjEnroll) ) {
				$strSubjEnr = "";
				foreach($strSubjEnroll as $strSubjEnrollValue) {
					$strSubjEnr .= "'" . escapestring($strSubjEnrollValue) . "',";
				}
				$strSubjEnrVal = trim(rtrim($strSubjEnr, ','));
											
				$result = $this->_DB->selectDB("SELECT s.`subj_idPK`, s.`sem_linker_idFK`, s.`total_units`
												FROM	`tbl_subject` s
												INNER JOIN `tbl_sem_linker` sl ON s.`sem_linker_idFK` = sl.`sem_linker_idPK` 
												WHERE	s.`subj_idPK` IN (" . $strSubjEnrVal . ") AND sl.`course_idFK` = '" . $strCourseID . "' AND s.`is_deleted` = 'N'");
				return $result;
			}
		}
			
		public function getStudSubjEnrollIDSemesterViaID($strSubjEnroll, $strCourseID = '') {
				
			$strCourseID = escapestring($strCourseID);
			
			if ( !empty($strSubjEnroll) ) {
				$strSubjEnr = "";
				foreach($strSubjEnroll as $strSubjEnrollValue) {
					$strSubjEnr .= "'" . escapestring($strSubjEnrollValue) . "',";
				}
				$strSubjEnrVal = trim(rtrim($strSubjEnr, ','));
											
				$result = $this->_DB->selectDB("SELECT DISTINCT `sem_linker_idFK`
												FROM	`tbl_subject` s
												INNER JOIN `tbl_sem_linker` sl ON s.`sem_linker_idFK` = sl.`sem_linker_idPK` 
												WHERE	s.`subj_idPK` IN (" . $strSubjEnrVal . ") AND sl.`course_idFK` = '" . $strCourseID . "' AND s.`is_deleted` = 'N'");
				return $result;
			}
		}
		
		public function getSemAlreadyTeken($studID, $courseID) {
			
			$studID   = escapestring($studID);
			$courseID = escapestring($courseID);
			
			return $this->_DB->selectDB("SELECT DISTINCT MAX(`sem_idFK`) AS `stud_sem_active` FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $studID . "' AND `course_idFK` = '" . $courseID . "' AND `stud_sem_active` != '0'");
			
		}
		
		public function getStudSemValidation($studID, $courseID, $semLinkerID, $yearID) {
			
			$studID   = escapestring($studID);
			$courseID = escapestring($courseID);
			$semLinkerID = escapestring($semLinkerID);
			$yearID = escapestring($yearID);

			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count` FROM `tbl_stud_sem` WHERE `stud_idFK` = '" . $studID . "' AND `course_idFK` = '" . $courseID . "' AND `sem_linker_idFK` = '" . $semLinkerID . "' AND `year_idFK` = '" . $yearID . "' AND `is_active` = 'N'");
			
		}
		
		public function getStudentEnrolled($semLinkerID, $strCourse, $strActiveyear) {
			
			$semLinkerID 	= escapestring($semLinkerID);
			$strCourse 		= escapestring($strCourse);
			$strActiveyear 	= escapestring($strActiveyear);
			
			if ( !empty($strActiveyear) ) {
				$whereAnd .= " AND `year_idFK` = '" . $strActiveyear . "'";
			}

			return $this->_DB->selectDB("SELECT `stud_sem_idPK`, `stud_idFK`, `course_idFK`, `sem_linker_idFK`, `is_regular` FROM `tbl_stud_sem` WHERE `course_idFK` = '" . $strCourse . "' AND `sem_linker_idFK` = '" . $semLinkerID . "' AND `is_deleted` = 'N' AND `is_active` = 'Y' AND `is_regular` = 'Y'" . $whereAnd);
			
		}
		
		public function getDefaultSections($strCourse, $strSectionID, $strSemesterID) {
			
			$strCourse 		= escapestring($strCourse);
			$strSectionID 	= escapestring($strSectionID);
			$strSemesterID 	= escapestring($strSemesterID);
			
			$whereAnd = '';
			if ( !empty($strSectionID) ) {
				$whereAnd .= " AND `section_idPK` = '" . $strSectionID . "'";
			}
			
			if ( !empty($strSemesterID) ) {
				$whereAnd .= " AND `sem_idFK` = '" . $strSemesterID . "'";
			}

			return $this->_DB->selectDB("SELECT `section_idPK`, `section_desc`, `course_idFK`, `no_stud` FROM `tbl_section` WHERE `course_idFK` = '" . $strCourse . "'" . $whereAnd . " AND `is_deleted` = 'N' ORDER BY `sem_idFK`, `section_idPK` ASC");
			
		}
		
		public function getStudentSections($strSectionID) {
			
			$strSectionID 	= escapestring($strSectionID);
			
			$whereAnd = '';
			if ( !empty($strSectionID) ) {
				$whereAnd .= "";
			}
			
			if ( !empty($strSemesterID) ) {
				$whereAnd .= " AND `sem_idFK` = '" . $strSemesterID . "'";
			}

			return $this->_DB->selectDB("SELECT `section_idPK`, `section_desc`, `course_idFK`, `no_stud` FROM `tbl_section` WHERE `course_idFK` = '" . $strCourse . "'" . $whereAnd . " AND `is_deleted` = 'N'  AND `section_idPK` = '" . $strSectionID . "'");
			
		}
		
		public function insertDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent) {
			
			$strSectionDesc = escapestring($strSectionDesc);
			$strCourse 		= escapestring($strCourse);
			$strSemester 		= escapestring($strSemester);
			$strNoStudent 	= escapestring($strNoStudent);

			$this->_DB->queryDB("INSERT INTO `tbl_section` (`section_desc`, `course_idFK`, `sem_idFK`, `no_stud`) VALUES ('" . $strSectionDesc . "', '" . $strCourse . "', '" . $strSemester . "', '" . $strNoStudent . "')");
			
			return mysql_insert_id();
		}
		
		public function updateDefaultSections($strSectionDesc, $strCourse, $strSemester, $strNoStudent, $strSectionID) {
			
			$strSectionDesc = escapestring($strSectionDesc);
			$strCourse 		= escapestring($strCourse);
			$strSemester 	= escapestring($strSemester);
			$strNoStudent 	= escapestring($strNoStudent);
			$strSectionID 	= escapestring($strSectionID);

			$this->_DB->queryDB("UPDATE `tbl_section` SET `section_desc` = '" . $strSectionDesc . "', `course_idFK` = '" . $strCourse . "', `sem_idFK` = '" . $strSemester . "', `no_stud` = '" . $strNoStudent . "' WHERE `section_idPK` = '" . $strSectionID . "'");
			
			return $strSectionID;
			
		}
		
		public function emptyStudSection($strSectionID) {
			
			$strSectionID 	= escapestring($strSectionID);

			$this->_DB->queryDB("DELETE FROM `tbl_stud_sec` WHERE `section_idFK` = '" . $strSectionID . "'");
			
		}
		
		public function updateDeptSection($strSectionID) {
			
			$strSectionID 	= escapestring($strSectionID);

			$this->_DB->queryDB("UPDATE `tbl_section` SET `is_deleted` = 'Y' WHERE `section_idPK` = '" . $strSectionID . "'");
			
		}
		
		public function insertStudentSectionSemester($strStudentSem, $strCourse, $strSectionID, $semLinkerID) {
			
			$strStudentSem  = escapestring($strStudentSem);
			$strCourse 		= escapestring($strCourse);
			$strSectionID 	= escapestring($strSectionID);
			$semLinkerID 	= escapestring($semLinkerID);

			$this->_DB->queryDB("INSERT INTO `tbl_stud_sec` (`stud_sem_idFK`, `course_idFK`, `section_idFK`, `sem_linker_idFK`) VALUES ('" . $strStudentSem . "', '" . $strCourse . "', '" . $strSectionID . "', '" . $semLinkerID . "')");
			
		}
		
		public function getStudentSectionSemesterAssigned($strCourse, $strSemLinker, $strYearID) {
			
			$strCourse 		= escapestring($strCourse);
			$strSemLinker 	= escapestring($strSemLinker);
			$strYearID 		= escapestring($strYearID);

			return $this->_DB->selectDB("SELECT 	DISTINCT ssem.`stud_idFK`
											FROM 	`tbl_stud_sec` ssec
											LEFT JOIN `tbl_stud_sem` ssem ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`
											WHERE ssec.`course_idFK` = '" . $strCourse . "'
												AND ssec.`sem_linker_idFK` = '" . $strSemLinker . "'
												AND ssec.`is_deleted` = 'N'
												AND ssem.`year_idFK` = '" . $strYearID . "'
												AND ssem.`is_deleted` = 'N'
												AND ssem.`is_active` = 'Y'
												AND ssem.`is_regular` = 'Y'");
			
		}
		
		public function getStudentSectionSemester($strCourse, $strSection, $strSemLinker, $strYearID) {
			
			$strCourse 		= escapestring($strCourse);
			$strSection 	= escapestring($strSection);
			$strSemLinker 	= escapestring($strSemLinker);
			$strYearID 		= escapestring($strYearID);

			return $this->_DB->selectDB("SELECT 	DISTINCT ssem.`stud_idFK`
											FROM 	`tbl_stud_sec` ssec
											LEFT JOIN `tbl_stud_sem` ssem ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`
											WHERE ssec.`course_idFK` = '" . $strCourse . "'
												AND ssec.`section_idFK` = '" . $strSection . "'
												AND ssec.`sem_linker_idFK` = '" . $strSemLinker . "'
												AND ssec.`is_deleted` = 'N'
												AND ssem.`year_idFK` = '" . $strYearID . "'
												AND ssem.`is_deleted` = 'N'
												AND ssem.`is_active` = 'Y'
												AND ssem.`is_regular` = 'Y'");
			
		}
		
		public function getStudentRequestIrregularSubject($strID) {

			$strID 	= escapestring($strID);
			
			return $this->_DB->selectDB2("SELECT s.`subj_desc`, s.`subj_code`, tsdi.`stud_subj_linker_idPK` FROM `tbl_stud_drop_subj_irreg` tsdi
										  INNER JOIN `tbl_subject` s
										  	ON (s.`subj_idPK` = tsdi.`subj_idFK`)
										  WHERE tsdi.`sdsi_idPK` = '" . $strID . "'");
			
		}
		
		public function getListingStudentSectionSemester($strCourse, $strSection, $strSemLinker) {
			
			$strCourse 		= escapestring($strCourse);
			$strSection 	= escapestring($strSection);
			$strSemLinker 	= escapestring($strSemLinker);

			return $this->_DB->selectDB("SELECT sc.`stud_sem_idFK`, sc.`course_idFK`, sc.`section_idFK`, sc.`sem_linker_idFK`, s.last_name, s.first_name
										 FROM `tbl_stud_sec` sc
										 INNER JOIN `tbl_stud_sem` ss ON ss.`stud_sem_idPK` = sc.`stud_sem_idFK`
										 INNER JOIN `tbl_students` s ON s.`stud_idPK` = ss.`stud_idFK` AND s.`is_deleted` = 'N' AND s.`is_active` = 'Y'
										 WHERE sc.`course_idFK` = '" . $strCourse . "' AND sc.`section_idFK` = '" . $strSection . "' AND sc.`sem_linker_idFK` = '" . $strSemLinker . "' AND sc.`is_deleted` = 'N'");
			
		}
		
		public function getStudentSectionEnrolled($strStudSemID) {
			
			$strStudSemID 	= escapestring($strStudSemID);

			return $this->_DB->selectDB2("SELECT COUNT(*) as stud_sec FROM `tbl_stud_sec` WHERE `stud_sem_idFK` = '" . $strStudSemID . "' AND `is_deleted` = 'N'");
			
		}
		
		public function getStudSemActiveStudent($semID, $semLinkerID) {
			
			$semID   		= escapestring($semID);
			$semLinkerID 	= escapestring($semLinkerID);
			
			return $this->_DB->selectDB("SELECT DISTINCT `stud_sem_active` FROM `tbl_stud_subj_linker` WHERE `stud_idFK` = '" . $studID . "' AND `course_idFK` = '" . $courseID . "'");
			
		}
		
		public function getStudSectionDesc($strStudID, $sstrCourseID, $strSemLinkerID) {
			
			$strStudID   	= escapestring($strStudID);
			$sstrCourseID 	= escapestring($sstrCourseID);
			$strSemLinkerID = escapestring($strSemLinkerID);
			
			return $this->_DB->selectDB2("SELECT	sec.`section_idPK`, sec.`section_desc`
										  FROM 	`tbl_stud_sec` ssec
										 	INNER JOIN `tbl_stud_sem` ssem
												ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`
											INNER JOIN tbl_section sec
												ON ssec.`section_idFK` = sec.`section_idPK`
										 WHERE ssem.`stud_idFK` = '" . $strStudID . "' AND ssem.`course_idFK` = '" . $sstrCourseID . "' AND ssem.`sem_linker_idFK` = '" . $strSemLinkerID . "' AND ssem.`is_deleted` = 'N' ORDER BY ssem.`stud_sem_idPK` DESC LIMIT 1");
			
		}
		
		public function arraySearchStudentInformation_ORIGINAL($strYearID, $strSearch, $pageLimit) {

			$whereCondition = '';
			$joinCondition  = '';
			$strYearID 	= escapestring($strYearID);

			if ( !empty($strSearch) ) {
				
				if ( !empty($strSearch['txtstudno']) ) {
					$whereCondition .= " AND s.`stud_no` = '" . $strSearch['txtstudno'] . "'";
				}
				
				if ( !empty($strSearch['txtfirst']) ) {
					$whereCondition .= " AND s.`first_name` LIKE '%" . $strSearch['txtfirst'] . "%'";
				}
				
				if ( !empty($strSearch['txtlast']) ) {
					$whereCondition .= " AND s.`last_name` 	LIKE '%" . $strSearch['txtlast'] . "%'";
				}
				
				if ( !empty($strSearch['txtsubject']) ) {
					$whereCondition   .= " AND tssl.`subj_idFK` = '" . $strSearch['txtsubject'] . "'";
					$joinConditionSubj = " INNER JOIN `tbl_stud_subj_linker` tssl ON tssl.`stud_idFK` = s.`stud_idPK` AND tssl.`year_idFK` = '" . $strYearID . "' AND tssl.`stud_sem_active` != '0'";
			
				}
				
				/*if ( !empty($strSearch['txtsemester']) ) {
					$whereCondition  .= " AND ssem.`sem_linker_idFK` = '" . $strSearch['txtsemester'] . "'";
					$joinConditionSem = " INNER JOIN `tbl_stud_sem` ssem ON ssem.`stud_idFK` = s.`stud_idPK` AND ssem.`year_idFK` = '" . $strYearID . "'";
				}*/
				if ( !empty($strSearch['txtsemester']) ) {
					$whereCondition  .= " AND ssem.`sem_idFK` = '" . $strSearch['txtsemester'] . "'";
					$joinConditionSem = " INNER JOIN `tbl_stud_sem` ssem ON ssem.`stud_idFK` = s.`stud_idPK` AND ssem.`year_idFK` = '" . $strYearID . "'";
				}
				
				
				if ( !empty($strSearch['txtsection']) ) {
					
					
					
					//if ( !empty($strSearch['txtsubject']) ) {
					$whereCondition .= " AND (sec.`section_idPK` = '"  . $strSearch['txtsection'] . "' OR  sec.`section_desc` IS NULL)";
					
					if ( !empty($strSearch['txtsubject']) ) {
						$joinConditionSubj .= "";
					}
					else {
						$joinConditionSubj = " INNER JOIN `tbl_stud_subj_linker` tssl ON tssl.`stud_idFK` = s.`stud_idPK` AND tssl.`year_idFK` = '" . $strYearID . "' AND tssl.`stud_sem_active` != '0'";
					}
						
					$joinConditionSec = '';
					if ( !empty($strSearch['txtsemester']) ) {
						$joinConditionSec .= " LEFT JOIN `tbl_stud_sec` ssec ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
					}
					else {
						$joinConditionSec .= " INNER JOIN `tbl_stud_sem` ssem ON ssem.`stud_idFK` = s.`stud_idPK` AND ssem.`year_idFK` = '" . $strYearID . "'
											   LEFT JOIN `tbl_stud_sec` ssec ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
					}
					
					$joinContidionnSectionISNULL = "LEFT JOIN `tbl_section` sec
														ON (sec.`section_idPK` = ssec.`section_idFK`)";
					//}
					//else {
					//	$whereCondition  .= " AND ssec.`section_idFK` = '" . $strSearch['txtsection'] . "'";
					//}
				}
			}
							
			return $this->_DB->selectDB("SELECT DISTINCT
												s.`stud_idPK`,
												s.`stud_no`,
												s.`log_user`,
												s.`picture`,
												s.`first_name`,
												s.`last_name`,
												s.`middle_name`,
												s.`birthdate`,
												s.`gender`,
												s.`email`,
												s.`contact_no`,
												s.`address`, 
												s.`guardian`,
												s.`first_reg`,
												s.`course_idFK`,
												c.`course_code`,
												c.`course_desc`,
												s.`is_deleted`
											FROM `tbl_students` s
											INNER JOIN `tbl_courses` c ON c.`course_idPK` = s.`course_idFK`
											" . $joinConditionSubj . $joinConditionSem . $joinConditionSec . $joinContidionnSectionISNULL . "
											WHERE s.`is_deleted` = 'N'" . $whereCondition . $pageLimit);

		}
		
		public function arraySearchStudentInformation($strYearID, $strSearch, $pageLimit) {

			$joinCondition  = '';
			$strYearID 	= escapestring($strYearID);

			if ( !empty($strSearch) ) {
				
				$strSearch['txtstudno'];
				$strSearch['txtfirst'];
				$strSearch['txtlast'];
				$strSearch['txtsubject'];
				$strSearch['txtsemester'];
				$strSearch['txtsection'];
				
				
				if ( !empty($strSearch['txtstudno']) ) {
					$whereStudno 	= " AND `stud_no` = '" . $strSearch['txtstudno'] . "'";
				}
				
				if ( !empty($strSearch['txtfirst']) ) {
					$whereFirstName = " AND `first_name` LIKE '%" . $strSearch['txtfirst'] . "%'";
				}
				
				if ( !empty($strSearch['txtlast']) ) {
					$whereLastName 	= " AND `last_name` 	LIKE '%" . $strSearch['txtlast'] . "%'";
				}
				
				if ( !empty($strSearch['txtsubject']) ) {
					$whereSubject   = " AND tssl.`subj_idFK` = '" . $strSearch['txtsubject'] . "'";
					$joinSubjLinker = " INNER JOIN `tbl_stud_subj_linker` tssl
											ON tssl.`stud_idFK` = s.`stud_idPK`";
											
											if ( !empty($strYearID) )	$joinSubjLinker .= " AND tssl.`year_idFK` = '" . $strYearID . "'";
											
					$joinSubjLinker .= " AND tssl.`stud_sem_active` != '0'
										INNER JOIN `tbl_subject` subj
											ON tssl.`subj_idFK` = subj.`subj_idPK`";
			
				}
				else {
					$joinSubjLinker = " INNER JOIN `tbl_stud_subj_linker` tssl
											ON tssl.`stud_idFK` = s.`stud_idPK`";
											
											if ( !empty($strYearID) ) $joinSubjLinker .= " AND tssl.`year_idFK` = '" . $strYearID . "'";
											
					$joinSubjLinker .= "AND tssl.`stud_sem_active` != '0'";
				}
				
				if ( !empty($strSearch['txtsemester']) ) {
					
					if ( !empty($strSearch['txtsubject']) ) {
						$whereSemLinker  = " AND subj.`sem_linker_idFK` = '" . $strSearch['txtsemester'] . "'";
					}
					else {
						$whereSemLinker  = " AND ssem.`sem_linker_idFK` = '" . $strSearch['txtsemester'] . "'";
					}
					
					$joinStudSem 	 = " INNER JOIN `tbl_stud_sem` ssem
											ON ssem.`stud_idFK` = s.`stud_idPK`";
											if ( !empty($strYearID) ) $joinStudSem .= " AND ssem.`year_idFK` = '" . $strYearID . "'";
						$joinStudSem 	 .= " AND ssem.`is_regular` = 'Y'";
											
					$join2StudSem 	 = " INNER JOIN `tbl_stud_sem` ssem
											ON ssem.`stud_idFK` = s.`stud_idPK`";
											if ( !empty($strYearID) ) $join2StudSem .= " AND ssem.`year_idFK` = '" . $strYearID . "'";
						$join2StudSem 	 .= " AND ssem.`is_regular` = 'N'";
				}
				
				if ( !empty($strSearch['txtsection']) ) {
					
					$where1Section = " AND sec.`section_idPK` = '"  . $strSearch['txtsection'] . "'";
					$where2Section = " AND pss.`section_idFK` = '"  . $strSearch['txtsection'] . "'";
					
					if ( !empty($strSearch['txtsemester']) ) {
						$joinStudSem  .= " LEFT JOIN `tbl_stud_sec` ssec
											ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
						$join2StudSem .= " LEFT JOIN `tbl_stud_sec` ssec
											ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
					}
					else {
						$joinStudSem  = " INNER JOIN `tbl_stud_sem` ssem
											ON ssem.`stud_idFK` = s.`stud_idPK`";
											if ( !empty($strYearID) ) $joinStudSem .= " AND ssem.`year_idFK` = '" . $strYearID . "'";
						$joinStudSem 	 .= " AND ssem.`is_regular` = 'Y'
										  LEFT JOIN `tbl_stud_sec` ssec
										  	ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
						
						$join2StudSem  = " INNER JOIN `tbl_stud_sem` ssem
											ON ssem.`stud_idFK` = s.`stud_idPK`";
											if ( !empty($strYearID) ) $join2StudSem .= " AND ssem.`year_idFK` = '" . $strYearID . "'";
						$join2StudSem 	 .= " AND ssem.`is_regular` = 'N'
										  LEFT JOIN `tbl_stud_sec` ssec
										  	ON ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`";
					}
					/*
					  LEFT JOIN `tbl_stud_sec` ssec
						ON (ssem.`stud_sem_idPK` = ssec.`stud_sem_idFK`)
					  LEFT JOIN `tbl_section` sec
						ON (sec.`section_idPK` = ssec.`section_idFK`)
					  INNER JOIN `tbl_stud_change_section_irreg` scsi
						ON tssl.stud_idFK = scsi.stud_idFK AND tssl.subj_idFK = scsi.subj_idFK
					  INNER JOIN `tbl_prof_subj_sched` pss
						ON pss.`prof_subj_sched_idPK` = scsi.`prof_subj_sched_idFK`
					*/
					$joinSection  = "LEFT JOIN `tbl_section` sec
										ON sec.`section_idPK` = ssec.`section_idFK`";
										
					$join2Section = "LEFT JOIN `tbl_section` sec
										ON sec.`section_idPK` = ssec.`section_idFK`
									INNER JOIN `tbl_stud_change_section_irreg` scsi
										ON tssl.`stud_idFK` = scsi.`stud_idFK` AND tssl.`subj_idFK` = scsi.`subj_idFK`
									INNER JOIN `tbl_prof_subj_sched` pss
										ON pss.`prof_subj_sched_idPK` = scsi.`prof_subj_sched_idFK`";
					
				
				}
			}
			
			$query = "SELECT * FROM (
														(SELECT DISTINCT
																s.`stud_idPK`,
																s.`stud_no`,
																s.`log_user`,
																s.`picture`,
																s.`first_name`,
																s.`last_name`,
																s.`middle_name`,
																s.`birthdate`,
																s.`gender`,
																s.`email`,
																s.`contact_no`,
																s.`address`, 
																s.`guardian`,
																s.`first_reg`,
																s.`course_idFK`,
																c.`course_code`,
																c.`course_desc`,
																s.`is_deleted`
															FROM `tbl_students` s
															INNER JOIN `tbl_courses` c ON c.`course_idPK` = s.`course_idFK`"
															. $joinSubjLinker
															. $joinStudSem
															. $joinSection
															. "WHERE s.`is_deleted` = 'N'"
															. $whereSubject
															. $whereSemLinker
															. $where1Section . ")" .
													" UNION
															(SELECT DISTINCT
																	s.`stud_idPK`,
																	s.`stud_no`,
																	s.`log_user`,
																	s.`picture`,
																	s.`first_name`,
																	s.`last_name`,
																	s.`middle_name`,
																	s.`birthdate`,
																	s.`gender`,
																	s.`email`,
																	s.`contact_no`,
																	s.`address`, 
																	s.`guardian`,
																	s.`first_reg`,
																	s.`course_idFK`,
																	c.`course_code`,
																	c.`course_desc`,
																	s.`is_deleted`
																FROM `tbl_students` s
																INNER JOIN `tbl_courses` c ON c.`course_idPK` = s.`course_idFK`"
																. $joinSubjLinker
																. $join2StudSem
																. $join2Section
																. "WHERE s.`is_deleted` = 'N'"
																. $whereSubject
																. $whereSemLinker
																. $where2Section . ")" .
											") AS tbl WHERE `is_deleted` = 'N'"
													  . $whereStudno
													  . $whereFirstName
													  . $whereLastName
													  . "ORDER BY last_name ASC"
													  . $pageLimit;
			//r_print($query);
			return $this->_DB->selectDB($query);

		}
		
		public function getListProfStudentPerSubj($strSemLinkerID, $strUserID, $strProfSujID, $strSectionID, $strSearch, $strLimit, $strYear) {
			
			$strSemLinkerID = escapestring($strSemLinkerID);
			$strUserID 		= escapestring($strUserID);
			$strProfSujID 	= escapestring($strProfSujID);
			$strSectionID 	= escapestring($strSectionID);
			$strSearch 		= escapestring($strSearch);
			$strYear 		= escapestring($strYear);
			
			$whereCondition = '';
			
			if ( !empty($strSearch) ) {
				$whereCondition .= " WHERE (`first_name` 		LIKE '%" . $strSearch . "%'
									  OR  `last_name` 		LIKE '%" . $strSearch . "%'
									  OR  `stud_no` 			= 	 '"  . $strSearch . "'
									  OR  `section_desc` 	= 	 '"  . $strSearch . "'
									  OR  `sem_code` 		= 	 '"  . $strSearch . "') ";
			}
			
			if ( !empty($strSectionID) ) {
				$whereConditionSectionReg   = " AND sec.`section_idPK` = '"  . $strSectionID . "'";
				$whereConditionSectionIRReg = " AND pss.`section_idFK` = '"  . $strSectionID . "'";
			}
			
			
			if ( !empty($strYear) ) {
				$whereYear   = " AND tssl.`year_idFK` = '"  . $strYear . "'";
			}
			
			return $this->_DB->selectDB("SELECT * FROM (
														(SELECT   DISTINCT
															  sem.`sem_code`,
															  sem.`sem_desc`,
															  ps.`subj_idFK`,
															  subj.`subj_desc`,
															  subj.`subj_code`,
															  tssl.`stud_subj_linker_idPK`,
															  tssl.`grade`,
															  tssl.`course_idFK`,
															  stud.`stud_idPK`,
															  stud.`stud_no`,
															  stud.`first_name`,
															  stud.`last_name`,
															  sec.`section_desc`
															FROM `tbl_prof_subj` ps
															  LEFT JOIN `tbl_stud_subj_linker` tssl
																ON (ps.`subj_idFK` = tssl.`subj_idFK`)
															  LEFT JOIN `tbl_students` s
																ON (tssl.`stud_idFK` = s.`stud_idPK`)
															  LEFT JOIN `tbl_subject` subj
																ON (ps.`subj_idFK` = subj.`subj_idPK`)
															  LEFT JOIN `tbl_students` stud
																ON (tssl.`stud_idFK` = stud.`stud_idPK`
																	AND stud.`is_deleted` = 'N'
																	AND stud.`is_active` = 'Y')
															  LEFT JOIN `tbl_semesters` sem
																ON (subj.sem_linker_idFK = sem.`sem_idPK`)
															  LEFT JOIN `tbl_stud_sem` ssem
																ON (tssl.`stud_idFK` = ssem.`stud_idFK`
																	AND tssl.`stud_sem_active` = ssem.`sem_linker_idFK`)
															  LEFT JOIN `tbl_stud_sec` ssec
																ON (ssem.`stud_sem_idPK` = ssec.`stud_sem_idFK`)
															  LEFT JOIN `tbl_section` sec
																ON (sec.`section_idPK` = ssec.`section_idFK`)
															WHERE ps.`user_idFK` = '" . $strUserID 		. "'
																AND ps.`prof_subj_idPK` = '" . $strProfSujID 	. "'
																AND tssl.`stud_sem_active` != '0'
																AND ssem.`is_regular` = 'Y'
																AND subj.sem_linker_idFK = '" . $strSemLinkerID 	. "'
																" . $whereConditionSectionReg . $whereYear . ")
														UNION
														
															(SELECT DISTINCT
																	  sem.`sem_code`,
																	  sem.`sem_desc`,
																	  ps.`subj_idFK`,
																	  subj.`subj_desc`,
																	  subj.`subj_code`,
																	  tssl.`stud_subj_linker_idPK`,
																	  tssl.`grade`,
																	  tssl.`course_idFK`,
																	  stud.`stud_idPK`,
																	  stud.`stud_no`,
																	  stud.`first_name`,
																	  stud.`last_name`,
																	  sec.`section_desc`
																	FROM `tbl_prof_subj` ps
																	  LEFT JOIN `tbl_stud_subj_linker` tssl
																		ON (ps.`subj_idFK` = tssl.`subj_idFK`)
																	  LEFT JOIN `tbl_students` s
																		ON (tssl.`stud_idFK` = s.`stud_idPK`)
																	  LEFT JOIN `tbl_subject` subj
																		ON (ps.`subj_idFK` = subj.`subj_idPK`)
																	  LEFT JOIN `tbl_students` stud
																		ON (tssl.`stud_idFK` = stud.`stud_idPK`
																			AND stud.`is_deleted` = 'N'
																			AND stud.`is_active` = 'Y')
																	  LEFT JOIN `tbl_semesters` sem
																		ON (subj.sem_linker_idFK = sem.`sem_idPK`)
																	  LEFT JOIN `tbl_stud_sem` ssem
																		ON (tssl.`stud_idFK` = ssem.`stud_idFK`
																			AND tssl.`stud_sem_active` = ssem.`sem_linker_idFK`)
																	  LEFT JOIN `tbl_stud_sec` ssec
																		ON (ssem.`stud_sem_idPK` = ssec.`stud_sem_idFK`)
																	  LEFT JOIN `tbl_section` sec
																		ON (sec.`section_idPK` = ssec.`section_idFK`)
																	  LEFT JOIN `tbl_stud_change_section_irreg` scsi
																		ON tssl.stud_idFK = scsi.stud_idFK AND tssl.subj_idFK = scsi.subj_idFK
																	  LEFT JOIN `tbl_prof_subj_sched` pss
																		ON pss.`prof_subj_sched_idPK` = scsi.`prof_subj_sched_idFK`
															WHERE ps.`user_idFK` = '" . $strUserID 		. "'
																AND ps.`prof_subj_idPK` = '" . $strProfSujID 	. "'
																AND tssl.`stud_sem_active` != '0'
																AND ssem.`is_regular` = 'N'
																AND subj.sem_linker_idFK = '" . $strSemLinkerID 	. "'
																" . $whereConditionSectionIRReg . $whereYear . ")
													) as `tbl` " . $whereCondition . " ORDER BY `last_name` " . $strLimit);
													
		}
		
		public function getProfSubjectLabLecHours($strUserID) {
			
			$strUserID 	= escapestring($strUserID);
														
			return $this->_DB->selectDB("SELECT DISTINCT  ps.`prof_subj_idPK`,
														  ps.`subj_idFK`,
														  s.`subj_desc`,
														  s.`subj_code`,
														  s.`lab_units`,
														  s.`lec_units`,
														  s.`total_units`,
														  s.`lec_lab_units`,
														  s.`total_hrs`,
														  s.`sem_linker_idFK`,
														  s.`is_saturday`,
														  sec.`section_idPK`,
														  sec.`section_desc`
														FROM `tbl_prof_subj` ps
														  INNER JOIN `tbl_subject` s
															ON (s.`subj_idPK` = ps.`subj_idFK`)
														  INNER JOIN `tbl_stud_sec` ss
															ON (ss.sem_linker_idFK = s.sem_linker_idFK)
														  INNER JOIN `tbl_section` sec
															ON (sec.`section_idPK` = ss.section_idFK)
														WHERE ps.`user_idFK` = '" . $strUserID . "'
														   AND ps.`is_deleted` = 'N'");		
			
		}
		
		public function getSchedDayTime($arrDaysSchedules, $strUserID, $strRoomID) {
			
			$strUserID 	 = escapestring($strUserID);
			$strRoomID 	 = escapestring($strRoomID);
			
			if ( !empty($arrDaysSchedules) ) {
				$strDaysScheduleFor = "";
				foreach($arrDaysSchedules as $strDaysSchedulesValue) {
					$strDaysScheduleFor .= "'" . escapestring($strDaysSchedulesValue) . "',";
				}
				$strDaysScheduleTrim = trim(rtrim($strDaysScheduleFor, ','));
												
				return $this->_DB->selectDB2("SELECT  st.`sched_time_idPK`,
													  st.`sched_int`,
													  st.`sched_day`,
													  st.`sched_from`,
													  st.`sched_to`,
													  st.`sched_key`,
													  st.`sched_break`
													FROM `tbl_sched_time` st
													WHERE st.`sched_break` = 'N'
														AND st.`sched_time_idPK` NOT IN (SELECT DISTINCT pss.`sched_time_idFK` FROM `tbl_prof_subj_sched` pss INNER JOIN `tbl_prof_subj` ps ON (ps.`prof_subj_idPK` = pss.prof_subj_idFK AND ps.user_idFK = '" . $strUserID . "')
																						 UNION
																			 			 SELECT DISTINCT pss.`sched_time_idFK` FROM `tbl_prof_subj_sched` pss WHERE pss.`room_idFK` = '" . $strRoomID . "' )
														AND st.`sched_day` IN (" . $strDaysScheduleTrim . ") AND st.`sched_break` = 'N' ORDER BY RAND() LIMIT 1");
				
			}
			
		}
		
		public function getSchedSaturdayTime() {
												
			return $this->_DB->selectDB2("SELECT `sched_time_idPK`, `sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_break` FROM `tbl_sched_time` WHERE `sched_int` = '6' AND `sched_break` = 'N' LIMIT 1");
				
		}
		
		public function getSchedTimeLimitSaveSaturday($strSchedInt, $strStartKey, $strLimit) {
												
			$strSchedInt = escapestring($strSchedInt);
			$strStartKey = escapestring($strStartKey);
			$strLimit 	 = escapestring($strLimit);
			
			return $this->_DB->selectDB("SELECT `sched_time_idPK` FROM `tbl_sched_time` WHERE `sched_int` = '" . $strSchedInt . "' AND `sched_key` >= '" . $strStartKey . "' AND `sched_break` = 'N' LIMIT " . $strLimit);
				
		}
		
		public function getSchedTimeLimitSave($strSchedInt, $strStartKey, $strLimit, $strUserID, $strRoomID) {
												
			$strSchedInt = escapestring($strSchedInt);
			$strStartKey = escapestring($strStartKey);
			$strLimit 	 = escapestring($strLimit);
			$strUserID 	 = escapestring($strUserID);
			$strRoomID 	 = escapestring($strRoomID);
			
			return $this->_DB->selectDB("SELECT st.`sched_time_idPK`
										 FROM 	`tbl_sched_time` st
										 WHERE 	st.`sched_int` = '" . $strSchedInt . "'
										 	AND st.`sched_key` >= '" . $strStartKey . "'
											AND st.`sched_break` = 'N'
											AND st.`sched_time_idPK` NOT IN (SELECT DISTINCT pss.`sched_time_idFK` FROM `tbl_prof_subj_sched` pss INNER JOIN `tbl_prof_subj` ps ON (ps.`prof_subj_idPK` = pss.prof_subj_idFK AND ps.user_idFK = '" . $strUserID . "')
																			 UNION
																			 SELECT DISTINCT pss.`sched_time_idFK` FROM `tbl_prof_subj_sched` pss WHERE pss.`room_idFK` = '" . $strRoomID . "' )
										 LIMIT " . $strLimit);
				
		}
		
		public function getRoomsForScheduling($strDept, $strType) {
			
			$strDept = escapestring($strDept);
			$strType = escapestring($strType);
			
			return $this->_DB->selectDB2("SELECT `room_idPK`, `room_desc` FROM `tbl_rooms` WHERE `dept_idFK` = '" . $strDept . "' AND `room_type` = '" . $strType . "' ORDER BY RAND() LIMIT 1");
			
		}
		
		public function getSectionsForScheduling($strSemLinkerID) {
			
			$strSemLinkerID = escapestring($strSemLinkerID);
			
			return $this->_DB->selectDB("SELECT `stud_sec_idPK`, `stud_sem_idFK`, `course_idFK`, `section_idFK` FROM `tbl_stud_sec` WHERE `sem_linker_idFK` = '" . $strSemLinkerID . "'");
			
		}
		
		public function getProfSubjectSchedules($strRoomID) {
			
			$strRoomID = escapestring($strRoomID);
			
			return $this->_DB->selectDB("SELECT `prof_subj_idFK`,
												`section_idPK`,
												`room_idFK`,
												`sched_time_idFK`,
												`lab_hrs`,
												`lec_hrs`
										FROM 	`tbl_prof_subj_sched`
										WHERE 	`room_idFK` = '" . $strRoomID . "'");
			
		}
		
		public function getProfSubjectGenerateSchedules($strUserID, $strSchedTimeID) {
			
			$strUserID = escapestring($strUserID);
			$strSchedTimeID = escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT DISTINCT subj.`subj_code`,
														  subj.`is_saturday`,
														  sec.`section_desc`,
														  r.`room_desc`,
														  pss.`lec_lab_both`,
														  pss.`sched_time_idFK`,
														  pss.`prof_subj_sched_idPK`
										 FROM `tbl_prof_subj_sched` pss
											INNER JOIN `tbl_prof_subj` ps
												ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
											INNER JOIN `tbl_section` sec
												ON (pss.`section_idFK` = sec.`section_idPK`)
											INNER JOIN `tbl_rooms` r
												ON (pss.`room_idFK` = r.`room_idPK`)
											INNER JOIN `tbl_subject` subj
												ON (ps.`subj_idFK` = subj.`subj_idPK`)
										 WHERE pss.`is_deleted` 		= 'N'
										   AND ps.`user_idFK` 			= '" . $strUserID . "'
										   AND  pss.`sched_time_idFK` 	= '" . $strSchedTimeID . "'
										   LIMIT 1");
		}
		
		public function getStudentActiveSubjectSchedules($strStudentID, $strSchedTimeID) {
			
			$strStudentID 	= escapestring($strStudentID);
			$strSchedTimeID = escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT  subj.`subj_code`,
												  subj.`subj_idPK`,
												  subj.`is_saturday`,
												  sec.`section_desc`,
												  r.`room_desc`,
												  pss.`lec_lab_both`,
												  pss.`sched_time_idFK`,
												  u.`last_name`,
												  u.`first_name`
												FROM `tbl_prof_subj_sched` pss
												  INNER JOIN `tbl_prof_subj` ps
													ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
												INNER JOIN `tbl_users_account` u
													ON (ps.`user_idFK` = u.`user_idPK`)
												  INNER JOIN `tbl_rooms` r
													ON (pss.`room_idFK` = r.`room_idPK`)
												  INNER JOIN `tbl_section` sec
													ON (pss.`section_idFK` = sec.`section_idPK`)
												  INNER JOIN `tbl_subject` subj
													ON (ps.`subj_idFK` = subj.`subj_idPK`)
												WHERE ps.`subj_idFK` IN(SELECT
																		  tssl.`subj_idFK`
																		FROM `tbl_stud_subj_linker` tssl
																		  INNER JOIN `tbl_stud_sem` ssem
																			ON (tssl.`stud_sem_active` = (SELECT
																											`sem_linker_idFK`
																										  FROM `tbl_stud_sem`
																										  WHERE `stud_idFK` = '" . $strStudentID . "'
																										  ORDER BY `stud_sem_idPK` DESC
																										  LIMIT 1)
																				AND tssl.stud_idFK = ssem.`stud_idFK`
																				AND ssem.`stud_idFK` = '" . $strStudentID . "'))
										   AND  pss.`sched_time_idFK` 	= '" . $strSchedTimeID . "'
										   LIMIT 1");
		}
		
		public function getSectionSubjectGenerateSchedules($strSectionID, $strSchedTimeID, $activeYear) {
			
			$strSectionID 	= escapestring($strSectionID);
			$strSchedTimeID = escapestring($strSchedTimeID);
			$activeYear 	= escapestring($activeYear);
			
			return $this->_DB->selectDB2("SELECT DISTINCT subj.`subj_idPK`,
														  subj.`subj_code`,
														  subj.`is_saturday`,
														  subj.`total_hrs`,
														  sec.`section_desc`,
														  r.`room_desc`,
														  pss.`lec_lab_both`,
														  pss.`sched_time_idFK`,
														  u.`last_name`,
														  u.`first_name`,
														  pss.`prof_subj_sched_idPK`,
														  ps.`prof_subj_idPK`
										 FROM `tbl_prof_subj_sched` pss
											INNER JOIN `tbl_prof_subj` ps
												ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
											INNER JOIN `tbl_users_account` u
												ON (ps.`user_idFK` = u.`user_idPK`)
											INNER JOIN `tbl_section` sec
												ON (pss.`section_idFK` = sec.`section_idPK`)
											INNER JOIN `tbl_rooms` r
												ON (pss.`room_idFK` = r.`room_idPK`)
											INNER JOIN `tbl_subject` subj
												ON (ps.`subj_idFK` = subj.`subj_idPK`)
										 WHERE pss.`is_deleted` 		= 'N'
										   AND pss.`section_idFK`		= '" . $strSectionID . "'
										   AND  pss.`sched_time_idFK` 	= '" . $strSchedTimeID . "'
										   AND pss.`year_idFK` 			= '" . $activeYear . "'
										   LIMIT 1");
		}
		
		public function getIrregularSubjectGenerateSchedules($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSchedTimeID, $strIsDeleted, $strSectionID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strCourseID 	 = escapestring($strCourseID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			$strYearID 	 	 = escapestring($strYearID);
			$strSchedTimeID  = escapestring($strSchedTimeID);
			$strSectionID    = escapestring($strSectionID);
			
			if ( $strIsDeleted === true ) {
				$whereIsDeleted = " AND  scsi.`is_deleted` = 'N'";
			}
			
			if ( !empty($strSectionID) ) {
				$whereIsSection = " AND  pss.`section_idFK` = '" . $strSectionID . "'";
			}
			return $this->_DB->selectDB2("SELECT DISTINCT
												  subj.`subj_idPK`,
												  subj.`subj_code`,
												  subj.`is_saturday`,
												  sec.`section_desc`,
												  r.`room_desc`,
												  pss.`lec_lab_both`,
												  pss.`sched_time_idFK`,
												  u.`last_name`,
												  u.`first_name`,
												  pss.`prof_subj_sched_idPK`,
												  scsi.`scsi_idPK`,
												  scsi.`is_accepted`,
												  scsi.`is_deleted`,
												  ps.`prof_subj_idPK`
											FROM `tbl_stud_change_section_irreg` scsi
												  INNER JOIN `tbl_subject` subj
													ON (scsi.`subj_idFK` = subj.`subj_idPK`)
												  INNER JOIN `tbl_prof_subj_sched` pss
													ON (scsi.`prof_subj_sched_idFK` = pss.`prof_subj_sched_idPK`)
												  INNER JOIN `tbl_rooms` r
													ON (pss.`room_idFK` = r.`room_idPK`)
												  INNER JOIN `tbl_prof_subj` ps
													ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
												  INNER JOIN `tbl_users_account` u
													ON (ps.`user_idFK` = u.`user_idPK`)
												  INNER JOIN `tbl_section` sec
													ON (pss.`section_idFK` = sec.`section_idPK`)
										 WHERE pss.`is_deleted` 			= 'N'
										   AND  scsi.`stud_idFK` 			= '" . $strStudentID 	. "'
										   AND  pss.`sched_time_idFK` 		= '" . $strSchedTimeID 	. "'
										   AND  scsi.`stud_idFK` 			= '" . $strStudentID 	. "'
										   AND  scsi.`course_idFK` 			= '" . $strCourseID 	. "'
										   AND  scsi.`sem_linker_idFK` 		= '" . $strSemLinkerID 	. "'
										   AND  scsi.`year_idFK` 			= '" . $strYearID 		. "'"
										   . $whereIsDeleted
										   . $whereIsSection);
		}
		
		public function getIrregularSubjectGenerateAutoSchedules($strSectionList, $strSubjectIDs, $strSchedTimeID) {
			
			$strSectionList = escapestring($strSectionList);
			$strSubjectIDs 	= escapestring($strSubjectIDs);
			$strSchedTimeID = escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT DISTINCT subj.`subj_idPK`,
														  subj.`subj_code`,
														  subj.`is_saturday`,
														  subj.`total_hrs`,
														  sec.`section_desc`,
														  r.`room_desc`,
														  pss.`lec_lab_both`,
														  pss.`sched_time_idFK`,
														  u.`last_name`,
														  u.`first_name`,
														  pss.`prof_subj_sched_idPK`
										 FROM `tbl_prof_subj_sched` pss
											INNER JOIN `tbl_prof_subj` ps
												ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
											INNER JOIN `tbl_users_account` u
												ON (ps.`user_idFK` = u.`user_idPK`)
											INNER JOIN `tbl_section` sec
												ON (pss.`section_idFK` = sec.`section_idPK`)
											INNER JOIN `tbl_rooms` r
												ON (pss.`room_idFK` = r.`room_idPK`)
											INNER JOIN `tbl_subject` subj
												ON (ps.`subj_idFK` = subj.`subj_idPK`)
										 WHERE pss.`is_deleted` 		= 'N'
										   AND pss.`section_idFK`		IN (" . $strSectionList . ")
										   AND ps.`subj_idFK`			IN (" . $strSubjectIDs . ")
										   AND  pss.`sched_time_idFK` 	= '" . $strSchedTimeID . "'
										   LIMIT 1");
		}
		
		public function getIrregularAutoGenerateSchedulesCount($strStudentID, $strCourseID, $strSemLinkerID, $strYearID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strCourseID 	 = escapestring($strCourseID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			$strYearID 	 	 = escapestring($strYearID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count`
											FROM `tbl_stud_change_section_irreg`
										 WHERE `is_deleted` 		= 'N'
										   AND  `stud_idFK` 		= '" . $strStudentID 	. "'
										   AND  `course_idFK` 		= '" . $strCourseID 	. "'
										   AND  `sem_linker_idFK` 	= '" . $strSemLinkerID 	. "'
										   AND  `year_idFK` 		= '" . $strYearID 		. "'");
		}
		
		public function getIrregularRequestedSchedule($strStudentID, $strSemLinkerID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			
			return $this->_DB->selectDB("SELECT DISTINCT subj.`subj_idPK`,
														  subj.`subj_code`,
														  subj.`is_saturday`,
														  subj.`total_hrs`,
														  sec.`section_desc`,
														  r.`room_desc`,
														  pss.`lec_lab_both`,
														  pss.`sched_time_idFK`,
														  u.`last_name`,
														  u.`first_name`,
														  pss.`prof_subj_sched_idPK`,
														  ss.`sched_day`,
														  ss.`sched_from`,
														  ss.`sched_to`,
														  scsi.`is_deleted`
										  FROM `tbl_stud_change_section_irreg` scsi
										    INNER JOIN `tbl_prof_subj_sched` pss
												ON (scsi.`prof_subj_sched_idFK` = pss.`prof_subj_sched_idPK`)
											INNER JOIN `tbl_sched_time` ss
												ON (ss.`sched_time_idPK` = pss.`sched_time_idFK`)
											INNER JOIN `tbl_prof_subj` ps
												ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
											INNER JOIN `tbl_users_account` u
												ON (ps.`user_idFK` = u.`user_idPK`)
											INNER JOIN `tbl_section` sec
												ON (pss.`section_idFK` = sec.`section_idPK`)
											INNER JOIN `tbl_rooms` r
												ON (pss.`room_idFK` = r.`room_idPK`)
											INNER JOIN `tbl_subject` subj
												ON (ps.`subj_idFK` = subj.`subj_idPK`)
										 WHERE scsi.`is_accepted` 		= 'P'
										   AND scsi.`stud_idFK` 		= '" . $strStudentID . "'
										   AND  scsi.`sem_linker_idFK` 	= '" . $strSemLinkerID . "'");
		}
		
		public function updateIrregularStudentSection($strStudentID, $strSemLinkerID, $strAction) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			$strAction  	 = escapestring($strAction);
			
			return $this->_DB->selectDB("SELECT scsi.`scsi_idPK`
										  FROM `tbl_stud_change_section_irreg` scsi
										 WHERE scsi.`is_accepted` 		= 'P'
										   AND scsi.`is_deleted` 		= '" . $strAction 		. "'
										   AND scsi.`stud_idFK` 		= '" . $strStudentID 	. "'
										   AND scsi.`sem_linker_idFK` 	= '" . $strSemLinkerID 	. "'");
			
		}
		
		public function requestIrregularStudentScheduleAccepted($strStudentID, $strSemLinkerID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			
			$this->_DB->queryDB("UPDATE 	`tbl_stud_change_section_irreg`
								SET 	`is_deleted` 		= 'N',
										`is_accepted` 		= 'Y'
								WHERE 	`is_accepted` 		= 'P'
									AND `is_deleted` 		= 'Y'
									AND `stud_idFK` 		= '" . $strStudentID . "'
											AND `sem_linker_idFK` 	= '" . $strSemLinkerID . "'");
											
			$this->_DB->queryDB("DELETE FROM	`tbl_stud_change_section_irreg`
								WHERE 	`is_accepted` 		= 'P'
									AND `is_deleted` 		= 'N'
									AND `stud_idFK` 		= '" . $strStudentID . "'
									AND `sem_linker_idFK` 	= '" . $strSemLinkerID . "'");
			
		}
		
		public function requestIrregularStudentScheduleDenied($strStudentID, $strSemLinkerID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			
			$this->_DB->queryDB("UPDATE 	`tbl_stud_change_section_irreg`
								SET 	`is_accepted` 		= 'N'
								WHERE 	`is_accepted` 		= 'P'
									AND `is_deleted` 		= 'N'
									AND `stud_idFK` 		= '" . $strStudentID . "'
									AND `sem_linker_idFK` 	= '" . $strSemLinkerID . "'");
											
			$this->_DB->queryDB("DELETE FROM	`tbl_stud_change_section_irreg`
								 WHERE 	`is_accepted` 		= 'P'
									AND `is_deleted` 		= 'Y'
									AND `stud_idFK` 		= '" . $strStudentID . "'
									AND `sem_linker_idFK` 	= '" . $strSemLinkerID . "'");
			
		}
		
		public function requestDeleteIrregularStudentSchedule($strStudNo, $strTable) {
			
			$strStudNo	= escapestring($strStudNo);
			$strTable	= escapestring($strTable);
			
			$this->_DB->queryDB("DELETE FROM  `tbl_stud_request` WHERE `stud_no` = '" . $strStudNo . "' AND `table_request` = '" . $strTable . "'");
			
		}
		
		public function SendRequestIrregularSchedule($strStudentID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count`
											FROM `tbl_stud_change_section_irreg`
										 WHERE `stud_idFK` 		= '" . $strStudentID 	. "'
										   AND  `is_accepted` 		= 'P'");
		}
		
		public function CancelRequestIrregularSchedule($strStudentID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_stud_change_section_irreg` WHERE `is_deleted` = 'Y' AND `is_accepted` = 'P' AND `stud_idFK` = '" . $strStudentID . "'");
			
			$this->_DB->queryDB("UPDATE `tbl_stud_change_section_irreg` SET `is_accepted` = NULL WHERE `is_deleted` = 'N' AND `is_accepted` = 'P' AND `stud_idFK` = '" . $strStudentID . "'");
			
		}
		
		
		public function RequestIrregularSchedule($strStudentNo, $strTableName) {
			
			$strStudentNo 	 = escapestring($strStudentNo);
			$strTableName 	 = escapestring($strTableName);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count`
										  FROM  `tbl_stud_request`
										 WHERE  `stud_no` 		= '" . $strStudentNo . "'
										 	AND `table_request`	= '" . $strTableName . "'");
		}
		
		public function getStudChangeSectionIrregSet($strStudentID, $strTimeID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strTimeID  	 = escapestring($strTimeID);
			
			return $this->_DB->selectDB2("SELECT  COUNT(*) AS `count`
											FROM `tbl_stud_change_section_irreg` scsi
											INNER JOIN `tbl_prof_subj_sched` pss ON scsi.`prof_subj_sched_idFK` = pss.`prof_subj_sched_idPK`
										 WHERE  scsi.`stud_idFK` 			= '" . $strStudentID 	. "'
										   AND  pss.`sched_time_idFK` 		= '" . $strTimeID 		. "'
										   AND  ((scsi.`is_accepted` 	   != 'P' OR  scsi.`is_accepted` IS NULL)
										     OR  (scsi.`is_accepted` 		= 'P' AND  scsi.`is_deleted` = 'Y'))");
		}
		
		public function getIrregularSubjectSchedulesiFrame($strStudentID, $strCourseID, $strSemLinkerID, $strYearID, $strSubjID) {
			
			$strStudentID 	 = escapestring($strStudentID);
			$strCourseID 	 = escapestring($strCourseID);
			$strSemLinkerID  = escapestring($strSemLinkerID);
			$strYearID 	 	 = escapestring($strYearID);
			$strSubjID  	 = escapestring($strSubjID);
			
			return $this->_DB->selectDB("SELECT  scsi.`prof_subj_sched_idFK`,
												  st.`sched_time_idPK`,
												  st.`sched_time`
											FROM `tbl_stud_change_section_irreg` scsi
											INNER JOIN `tbl_prof_subj_sched` pss ON scsi.`prof_subj_sched_idFK` = pss.`prof_subj_sched_idPK`
											INNER JOIN `tbl_sched_time` st 		 ON pss.`sched_time_idFK` = st.`sched_time_idPK`
										 WHERE  scsi.`subj_idFK` 			= '" . $strSubjID 	. "'
										   AND  scsi.`stud_idFK` 			= '" . $strStudentID 	. "'
										   AND  scsi.`course_idFK` 			= '" . $strCourseID 	. "'
										   AND  scsi.`sem_linker_idFK` 		= '" . $strSemLinkerID 	. "'
										   AND  scsi.`year_idFK` 			= '" . $strYearID 		. "'
										   AND  ((scsi.`is_accepted` 		!= 'P' OR  scsi.`is_accepted` IS NULL)
										     OR  (scsi.`is_accepted` 		= 'P' AND  scsi.`is_deleted` = 'Y'))");
		}
		
		public function getStudentSectionSubjectGenerateSchedules($strStudID, $strCourseID, $strSemLinkerID, $strSectionID, $strSchedTimeID) {
			
			$strStudID 		= escapestring($strStudID);
			$strCourseID 	= escapestring($strCourseID);
			$strSemLinkerID = escapestring($strSemLinkerID);
			$strSectionID 	= escapestring($strSectionID);
			$strSchedTimeID = escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT DISTINCT subj.`subj_idPK`,
														  subj.`subj_code`,
														  subj.`is_saturday`,
														  sec.`section_desc`,
														  r.`room_desc`,
														  pss.`lec_lab_both`,
														  pss.`sched_time_idFK`,
														  u.`last_name`,
														  u.`first_name`
										 FROM `tbl_prof_subj_sched` pss
											INNER JOIN `tbl_prof_subj` ps
												ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`)
											INNER JOIN `tbl_users_account` u
												ON (ps.`user_idFK` = u.`user_idPK`)
											INNER JOIN `tbl_section` sec
												ON (pss.`section_idFK` = sec.`section_idPK`)
											INNER JOIN `tbl_rooms` r
												ON (pss.`room_idFK` = r.`room_idPK`)
											INNER JOIN `tbl_subject` subj
												ON (ps.`subj_idFK` = subj.`subj_idPK`)
										 WHERE pss.`is_deleted` 		= 'N'
										   AND pss.`section_idFK`		= '" . $strSectionID . "'
										   AND  pss.`sched_time_idFK` 	= '" . $strSchedTimeID . "'
										   AND  ps.`subj_idFK` 	IN (SELECT DISTINCT tssl.`subj_idFK`
																	 FROM 			`tbl_stud_subj_linker` tssl
																	 WHERE 			tssl.`stud_idFK` 		= '" . $strStudID . "'
																		AND 		tssl.`course_idFK` 		= '" . $strCourseID . "'
																		AND 		tssl.`stud_sem_active` 	= '" . $strSemLinkerID . "'
																		AND 		tssl.`is_deleted` = 'N')
										   LIMIT 1");
		}
		
		public function getProfSubjectSchedulesIfHaveSched($strUserID) {
			
			$strUserID = escapestring($strUserID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) AS `count` FROM `tbl_prof_subj_sched` pss INNER JOIN `tbl_prof_subj` ps ON (pss.`prof_subj_idFK` = ps.`prof_subj_idPK`) WHERE pss.`is_deleted` = 'N' AND pss.`temp_sched` = 'N' AND ps.`user_idFK` 	= '" . $strUserID . "'");
			
		}
		
		public function getSimilarProfSubjSchedulesProf($strSchedTimeID) {
			
			$strSchedTimeID	= escapestring($strSchedTimeID);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) as `count` FROM `tbl_prof_subj_sched` WHERE `sched_time_idFK` = '" . $strSchedTimeID . "'");
			
		}
		
		public function getProfSubjSchedActive($strYear) {
			
			$strYear	= escapestring($strYear);
			
			return $this->_DB->selectDB2("SELECT COUNT(*) as `count` FROM `tbl_prof_subj_sched` WHERE `year_idFK` = '" . $strYear . "'");
			
		}
		
		public function getScheduleTimePerSubj($strSubjID) {
			
			$strSubjID	= escapestring($strSubjID);
			
			return $this->_DB->selectDB("SELECT	  pss.`prof_subj_sched_idPK`,
												  st.`sched_day`,
												  st.`sched_from`,
												  st.`sched_to`,
												  r.`room_desc`,
												  sec.`section_desc`
												FROM `tbl_prof_subj_sched` pss
												  INNER JOIN `tbl_rooms` r
													ON pss.`room_idFK` = r.`room_idPK`
												  INNER JOIN `tbl_section` sec
													ON pss.`section_idFK` = sec.`section_idPK`
												  INNER JOIN `tbl_sched_time` st
													ON pss.`sched_time_idFK` = st.`sched_time_idPK`
												  INNER JOIN `tbl_prof_subj` ps
													ON pss.`prof_subj_idFK` = ps.`prof_subj_idPK` AND ps.`subj_idFK` = '" . $strSubjID . "'
												 ORDER BY pss.`prof_subj_sched_idPK` ASC");
			
		}
		
		public function insertProfSubjSchedTemp($strArray) {
			
			$prof_subj_id	= escapestring($strArray['prof_subj']);
			$section_id		= escapestring($strArray['section']);
			$room_id		= escapestring($strArray['room']);
			$sched_time_id	= escapestring($strArray['sched_time']);
			$lec_lab_both	= escapestring($strArray['lec_lab']);
			$year_id		= escapestring($strArray['year_id']);
			
			$this->_DB->queryDB("INSERT INTO `tbl_prof_subj_sched` (`prof_subj_idFK`, `section_idFK`, `room_idFK`, `sched_time_idFK`, `lec_lab_both`, `year_idFK`) VALUES ('" . $prof_subj_id . "', '" . $section_id . "', '" . $room_id. "', '" . $sched_time_id . "', '" . $lec_lab_both . "', '" . $year_id . "')");
			
		}
		
		public function deleteProfSubjSchedTemp($strUserID) {
			
			$strUserID	= escapestring($strUserID);
			
			$this->_DB->queryDB("DELETE pss.* FROM `tbl_prof_subj_sched` pss INNER JOIN `tbl_prof_subj` ps ON pss.`prof_subj_idFK` = ps.`prof_subj_idPK` WHERE ps.`user_idFK` = '" . $strUserID . "' AND ps.`is_deleted` = 'N' AND pss.`is_deleted` = 'N' AND pss.`temp_sched` = 'Y'");
			
		}
		
		public function saveSchedulesRemoveTemp($strUserID) {
			
			$strUserID	= escapestring($strUserID);
			
			$this->_DB->queryDB("UPDATE `tbl_prof_subj_sched` pss INNER JOIN `tbl_prof_subj` ps ON pss.`prof_subj_idFK` = ps.`prof_subj_idPK` SET pss.`temp_sched` = 'N' WHERE ps.`user_idFK` = '" . $strUserID . "' AND ps.`is_deleted` = 'N' AND pss.`is_deleted` = 'N' AND pss.`temp_sched` = 'Y'");
			
		}
		
		public function getListSectionProfStudenPerSubj($strSemLinkerID, $strUserID, $strProfSujID) {
			
			$strSemLinkerID = escapestring($strSemLinkerID);
			$strUserID 		= escapestring($strUserID);
			$strProfSujID 	= escapestring($strProfSujID);
			
			return $this->_DB->selectDB("SELECT DISTINCT  pss.`section_idFK`,
														  sec.`section_idPK`,
														  sec.`section_desc`
										FROM `tbl_prof_subj` ps
										  INNER JOIN `tbl_prof_subj_sched` pss
											ON (ps.`prof_subj_idPK` = pss.`prof_subj_idFK`)
										  INNER JOIN `tbl_stud_subj_linker` tssl
											ON ps.`subj_idFK` = tssl.`subj_idFK`
										  INNER JOIN `tbl_section` sec
											ON pss.`section_idFK` = sec.`section_idPK`
										WHERE ps.`user_idFK`			= '" . $strUserID 		. "'
													AND ps.`prof_subj_idPK` 	= '" . $strProfSujID 	. "'
													AND tssl.`stud_sem_active`	= '" . $strSemLinkerID 	. "'
												    AND ps.`is_deleted` = 'N'
										ORDER BY sec.`section_idPK`");
			
		}
		
		public function insertStudentRequest($strArray) {
			
			$stud_no		= escapestring($strArray['stud_no']);
			$first_name		= escapestring($strArray['first_name']);
			$last_name		= escapestring($strArray['last_name']);
			$middle_name	= escapestring($strArray['middle_name']);
			$email			= escapestring($strArray['email']);
			$message		= escapestring($strArray['message']);
			$type			= escapestring($strArray['type']);
			
			$table_request	= ( !empty($strArray['table_request']) ) ? escapestring($strArray['table_request']) : '';
			$table_id		= ( !empty($strArray['table_id']) ) 	 ? escapestring($strArray['table_id']) 		: '';
			
			$this->_DB->queryDB("INSERT INTO `tbl_stud_request` (`stud_no`, `first_name`, `last_name`, `middle_name`, `email`, `message`, `request_type`, `table_request`, `table_id`) VALUES ('" . $stud_no	 . "', '" . $first_name . "', '" . $last_name. "', '" . $middle_name . "', '" . $email . "', '" . $message . "', '" . $type . "', '" . $table_request . "', '" . $table_id . "')");
			
		}
		
		public function getStudentListRequest($strSearch, $strLimit) {
			
			$strSearch 		= escapestring($strSearch);
			$whereCondition = '';
			
			if ( !empty($strSearch) ) {
				$whereCondition .= " AND (s.`first_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`last_name` 	LIKE '%" . $strSearch . "%'
									  OR  s.`email` 		LIKE '%" . $strSearch . "%'
									  OR  s.`stud_no` 		    = '" . $strSearch . "') ";
			}
			
			return $this->_DB->selectDB("SELECT s.`stud_idPK`,
												s.`stud_no`,
												s.`first_name`,
												s.`last_name`,
												sr.`email`,
												sr.`table_request`,
												sr.`table_id`,
												sr.`request_type`
										  FROM `tbl_stud_request` sr
										  INNER JOIN `tbl_students` s
										  	ON (sr.`stud_no` = s.`stud_no` AND sr.`first_name` = s.`first_name` AND sr.`last_name` = s.`last_name`)
										 WHERE sr.`is_deleted` = 'N'" . $whereCondition . $strLimit);
			
		}
		
		public function getStudentByhStudNo($strStudNo) {
			
			$strStudNo	= escapestring($strStudNo);
			
			return $this->_DB->selectDB2("SELECT `email` FROM `tbl_stud_request` WHERE `stud_no` = '" . $strStudNo . "' LIMIT 1");
			
		}
		
		public function updateStudentRequestPassword($strArray, $strStudID) {
			
			$username	= escapestring($strArray['username']);
			$password	= escapestring($strArray['password']);
			$strStudID	= escapestring($strStudID);
			
			$this->_DB->queryDB("UPDATE `tbl_students` SET `log_user` = '" . $username . "', `log_pass` = '" . md5($password) . "' WHERE `stud_idPK` = '" . $strStudID . "'");
			
		}
		
		public function deleteStudentRequestPassword($strStudNo) {
			
			$strStudNo	= escapestring($strStudNo);
			
			$this->_DB->queryDB("DELETE FROM  `tbl_stud_request` WHERE `stud_no` = '" . $strStudNo . "'");
			
		}
		
		public function getProfSubjList($strUserID, $strProfSubj) {
			
			$strUserID	= escapestring($strUserID);
			
			if ( !empty($strProfSubj)) {
				$whereProfSubj = " AND ps.`prof_subj_idPK` = '" . escapestring($strProfSubj) . "'";
			}
			
			return $this->_DB->selectDB("SELECT DISTINCT ps.`prof_subj_idPK`, c.`course_code`, s.`subj_desc`, s.`subj_code`, s.`total_hrs`, s.`total_units`, s.`lec_units`, s.`lab_units`, s.`lec_lab_units`
										FROM 		`tbl_prof_subj` ps
										INNER JOIN  `tbl_subject` s ON s.`subj_idPK` = ps.`subj_idFK`
										LEFT JOIN `tbl_sem_linker` sl ON sl.`sem_linker_idPK` = s.`sem_linker_idFK`
										LEFT JOIN `tbl_courses` c ON c.`course_idPK` = sl.`course_idFK`
										WHERE 		ps.`user_idFK` = '" . $strUserID . "' AND ps.`is_deleted` = 'N'" . $whereProfSubj);
			
		}
		
		public function getProfSectionList($strSchedTimeID, $strSemesterLinkerID) {
			
			$whereProfSection = '';
			
			if ( !empty($strSchedTimeID)) {
				$whereProfSection .= " AND sec.`section_idPK` NOT IN(SELECT pss.`section_idFK` FROM `tbl_prof_subj_sched` pss WHERE pss.`sched_time_idFK` = '" . escapestring($strSchedTimeID) . "')";
			}
			
			if ( !empty($strSemesterLinkerID)) {
				$whereProfSection .= " AND sec.`sem_idFK` = '" . $strSemesterLinkerID . "'";
			}
			
			return $this->_DB->selectDB("SELECT sec.`section_idPK`, sec.`section_desc` FROM `tbl_section` sec WHERE  sec.`is_deleted` = 'N'" . $whereProfSection . "ORDER BY sec.`sem_idFK`");
			
		}
		
		public function getProfRoomList($strSchedTimeID) {
			
			if ( !empty($strSchedTimeID)) {
				$whereProfSection = " WHERE r.`room_idPK` NOT IN(SELECT pss.`room_idFK` FROM `tbl_prof_subj_sched` pss WHERE pss.`sched_time_idFK` = '" . escapestring($strSchedTimeID) . "') AND r.`is_deleted` = 'N'";
			}
			
			return $this->_DB->selectDB("SELECT r.`room_idPK`, r.`room_desc` FROM `tbl_rooms` r" . $whereProfSection);
			
		}
		
		public function getProfSubjActive($strProfSubj, $strSection) {
			
			$strProfSubj	= escapestring($strProfSubj);
			$whereSection = '';
			if ( !empty($strSection)) {
				$whereSection .= " AND pss.`section_idFK` = '" . escapestring($strSection) . "'";
			}
			
			return $this->_DB->selectDB("SELECT pss.`lec_lab_both`, st.sched_time
										FROM 		`tbl_prof_subj_sched` pss
										INNER JOIN `tbl_sched_time` st ON st.sched_time_idPK = pss.sched_time_idFK
										WHERE 		 pss.`prof_subj_idFK` = '" . $strProfSubj . "'" . $whereSection);
			
		}
		
		public function getProfSubjActiveIrregular($strProfSubj, $strSection, $strSubject) {
			
			$strProfSubj = escapestring($strProfSubj);
			$strSection	 = escapestring($strSection);
			$strSubject	 = escapestring($strSubject);
			
			return $this->_DB->selectDB("SELECT 	 pss.`prof_subj_sched_idPK`
										 FROM 		`tbl_prof_subj_sched` pss
										 INNER JOIN `tbl_prof_subj` ps ON ps.prof_subj_idPK = pss.prof_subj_idFK
										 INNER JOIN `tbl_sched_time` st ON st.sched_time_idPK = pss.sched_time_idFK
										 WHERE 		 pss.`prof_subj_idFK` = '" . $strProfSubj . "'
										 AND 		 pss.`section_idFK`   = '" . $strSection  . "'
										 AND 		 ps.`subj_idFK`  	  = '" . $strSubject  . "'");
			
		}
		
		public function deleteTimeSchedule($strProfSubjSchedID) {
			
			$strProfSubjSchedID	= escapestring($strProfSubjSchedID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_prof_subj_sched` WHERE  `prof_subj_sched_idPK` = '" . $strProfSubjSchedID . "'");
			
		}
		
		public function insertStudentChangeSection($studID, $courseID, $semLinkerID, $yearID, $currentSectionID, $changeSectionID) {

			$studID 			= escapestring($studID);
			$courseID 			= escapestring($courseID);
			$semLinkerID 		= escapestring($semLinkerID);
			$yearID 			= escapestring($yearID);
			$currentSectionID 	= escapestring($currentSectionID);
			$changeSectionID 	= escapestring($changeSectionID);
			
			$this->_DB->queryDB("INSERT INTO `tbl_stud_change_section` (`stud_idFK`, `course_idFK`, `sem_linker_idFK`, `year_idFK`, `stud_sec_idFK`, `section_idFK`)
								 VALUES ('" . $studID . "','" . $courseID . "','" . $semLinkerID . "','" . $yearID . "','" . $currentSectionID . "','" . $changeSectionID . "')");
			return mysql_insert_id();
			
		}
		
		public function updateStudentChangeSection($strSCSID, $strStatus) {

			$strSCSID 	= escapestring($strSCSID);
			$strStatus 	= escapestring($strStatus);

			$this->_DB->queryDB("UPDATE `tbl_stud_change_section` SET `is_accepted` = '" . $strStatus . "', `is_deleted` = 'Y' WHERE `scs_idPK` = '" . $strSCSID . "'");
			
		}
		
		public function getStudentChangeSectionActive($studID, $courseID, $semLinkerID, $yearID) {

			$studID 			= escapestring($studID);
			$courseID 			= escapestring($courseID);
			$semLinkerID 		= escapestring($semLinkerID);
			$yearID 			= escapestring($yearID);
			
			return $this->_DB->selectDB2("SELECT `scs_idPK`, `is_accepted`, `is_deleted`, `section_idFK`
										  FROM 	 `tbl_stud_change_section`
										  WHERE  `stud_idFK` 		= '" . $studID 			 . "'
										  	AND  `course_idFK` 		= '" . $courseID		 . "'
											AND  `sem_linker_idFK` 	= '" . $semLinkerID 	 . "'
											AND  `year_idFK` 		= '" . $yearID 			 . "'");
			
		}
		
		public function IrregularSetScheduleStudent($strArray, $profSubjSchedID, $strAccepted, $strDeleted) {
			
			$stud_id 			= escapestring($strArray['stud_id']);
			$course_id 			= escapestring($strArray['course_id']);
			$sem_linker_id 		= escapestring($strArray['sem_linker_id']);
			$year_id 			= escapestring($strArray['year_id']);
			$subj_id 			= escapestring($strArray['subj_id']);
			$prof_subj_sched_id = escapestring($strArray['prof_subj_sched_id']);
			$this->_DB->queryDB("INSERT INTO `tbl_stud_change_section_irreg` (`stud_idFK`, `course_idFK`, `sem_linker_idFK`, `year_idFK`, `subj_idFK`, `prof_subj_sched_idFK`, `is_accepted`, `is_deleted`)
								 VALUES ('" . $stud_id . "','" . $course_id . "','" . $sem_linker_id . "','" . $year_id . "','" . $subj_id . "','" . $prof_subj_sched_id . "','" . $strAccepted . "','" . $strDeleted . "')");
			
			return mysql_insert_id();
		}
		
		//public function IrregularDeleteScheduleStudent($strSCSIID) {
		public function IrregularDeleteScheduleStudent($strSubjLinker, $strSubjGroup) {
			
			$strSubjLinker	= escapestring($strSubjLinker);
			$strSubjGroup	= escapestring($strSubjGroup);
			
			$this->_DB->queryDB("UPDATE `tbl_stud_change_section_irreg` SET `is_accepted` = 'P' WHERE `sem_linker_idFK` = '" . $strSubjLinker . "' AND `subj_idFK` = '" . $strSubjGroup . "'");
			
		}
		
		public function IrregularDeleteScheduleStudentRegistrar($strSCSIID) {
			
			$strSCSIID	= escapestring($strSCSIID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_stud_change_section_irreg` WHERE `scsi_idPK` = '" . $strSCSIID . "'");
			
		}
		
		public function SaveTimeSchedule($strArray) {
			
			$sched_int 		= escapestring($strArray['sched_int']);
			$sched_day 		= escapestring($strArray['sched_day']);
			$sched_from 	= escapestring($strArray['sched_from']);
			$sched_to 		= escapestring($strArray['sched_to']);
			$sched_key 		= escapestring($strArray['sched_key']);
			$sched_time 	= escapestring($strArray['sched_time']);
			$sched_break 	= escapestring($strArray['sched_break']);
			$year_id 		= escapestring($strArray['year_id']);
			
			$this->_DB->queryDB("INSERT INTO `tbl_sched_time` (`sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_break`, `sched_time`, `year_idFK`)
								 VALUES ('" . $sched_int . "', '" . $sched_day . "', '" . $sched_from . "', '" . $sched_to . "', '" . $sched_key . "', '" . $sched_break . "', '" . $sched_time . "', '" . $year_id . "')");
			
		}
		
		public function SaveTempTimeSchedule($strArray) {
			
			$sched_int 		= escapestring($strArray['sched_int']);
			$sched_day 		= escapestring($strArray['sched_day']);
			$sched_from 	= escapestring($strArray['sched_from']);
			$sched_to 		= escapestring($strArray['sched_to']);
			$sched_key 		= escapestring($strArray['sched_key']);
			$sched_time 	= escapestring($strArray['sched_time']);
			$sched_break 	= escapestring($strArray['sched_break']);
			$year_id 		= escapestring($strArray['year_id']);
			$trigger_id 	= escapestring($strArray['trigger_id']);
			
			$this->_DB->queryDB("INSERT INTO `tbl_sched_time_temp` (`sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_break`, `sched_time`, `year_idFK`, `trigger_id`)
								 VALUES ('" . $sched_int . "', '" . $sched_day . "', '" . $sched_from . "', '" . $sched_to . "', '" . $sched_key . "', '" . $sched_break . "', '" . $sched_time . "', '" . $year_id . "', '" . $trigger_id . "')");
			
		}
		
		public function getTimeSchedule($strField, $strYear, $strInt, $strID) {
			
			$strField 	= escapestring($strField);
			$strYear 	= escapestring($strYear);
			$whereInt   = '';
			
			if( !empty($strInt) ) {
				$whereInt .= " AND `sched_int` = '" . escapestring($strInt) . "'";
			}
			
			if( !empty($strID) ) {
				$whereInt .= " AND `sched_time_idPK` = '" . escapestring($strID) . "'";
			}
			
			return $this->_DB->selectDB("SELECT `" . $strField . "`
										  FROM 	 `tbl_sched_time`
										  WHERE  `year_idFK` = '" . $strYear . "'" . $whereInt);
		}
		
		public function getTempLastSchedule($strYear) {
			
			$strYear 	= escapestring($strYear);
			
			return $this->_DB->selectDB2("SELECT `sched_time_idPK`, `sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_time`, `sched_break`, `year_idFK`, `trigger_id`
										  FROM 	 `tbl_sched_time_temp`
										  WHERE  `year_idFK` = '" . $strYear . "'
										  ORDER BY `sched_time_idPK` DESC LIMIT 1");
		}
		
		public function getTempSchedule($strYear) {
			
			$strYear 	= escapestring($strYear);
			
			return $this->_DB->selectDB("SELECT DISTINCT `sched_from`, `sched_to`, `sched_key`, `sched_time`, `sched_break`, `year_idFK`, `trigger_id`
										  FROM 	 `tbl_sched_time_temp`
										  WHERE  `year_idFK` = '" . $strYear . "'");
		}
		
		public function getTempAllSchedule($strYear) {
			
			$strYear 	= escapestring($strYear);
			
			return $this->_DB->selectDB("SELECT `sched_time_idPK`, `sched_int`, `sched_day`, `sched_from`, `sched_to`, `sched_key`, `sched_time`, `sched_break`, `year_idFK`, `trigger_id`
										  FROM 	 `tbl_sched_time_temp`
										  WHERE  `year_idFK` = '" . $strYear . "'");
		}
		
		function deleteTempSchedule($strTriggerID) {
			
			$strTriggerID 	= escapestring($strTriggerID);
			
			$this->_DB->queryDB("DELETE FROM `tbl_sched_time_temp` WHERE `trigger_id` = '" . $strTriggerID . "'");
		
		}
		
		function truncateTempSchedule() {
			
			$this->_DB->queryDB("TRUNCATE TABLE `tbl_sched_time_temp`");
		
		}
		
		function changeTimeScheduleActive($strYear) {
			
			$strYear 	= escapestring($strYear);
			
			$this->_DB->queryDB("DELETE FROM `tbl_sched_time` WHERE `year_idFK` = '" . $strYear . "'");
		
		}
		
		public function getStudentsIncGrade($strSearch, $pageLimit) {

			if ( !empty($strSearch) ) {
				
				$strSearch['txtstudno'];
				$strSearch['txtsubject'];
				$strSearch['txtsemester'];
				
				if ( !empty($strSearch['txtstudno']) ) {
					$studNoWhere = " AND s.`stud_no` = '" . $strSearch['txtstudno'] . "'";
				}
				
				if ( !empty($strSearch['txtsubject']) ) {
					$subjectWhere = " AND tssl.`subj_idFK` = '" . $strSearch['txtsubject'] . "'";
				}
				
				if ( !empty($strSearch['txtsemester']) ) {
					$semesterWhere  = " AND sl.`sem_idFK` = '" . $strSearch['txtsemester'] . "'";
				}
				
			}
			
			return $this->_DB->selectDB("SELECT DISTINCT
												sem.`sem_code`,
												sem.`sem_desc`,
												tssl.`subj_idFK`,
												subj.`subj_desc`,
												subj.`subj_code`,
												tssl.`stud_subj_linker_idPK`,
												tssl.`grade`,
												tssl.`course_idFK`,
												s.`stud_idPK`,
												s.`stud_no`,
												s.`first_name`,
												s.`last_name`,
												sec.`section_desc`,
												y.`year_from`,
												y.`year_to`,
												c.`course_code`
										 FROM `tbl_stud_subj_linker` tssl
										 LEFT JOIN `tbl_students` 	s  ON s.`stud_idPK`   		= tssl.`stud_idFK`
										 LEFT JOIN `tbl_subject` 	subj  ON subj.`subj_idPK`   = tssl.`subj_idFK`
										 LEFT JOIN `tbl_courses`  	c  ON c.`course_idPK` 		= tssl.`course_idFK`
										 LEFT JOIN `tbl_year`     	y  ON y.`year_idPK`   		= tssl.`year_idFK`
										 LEFT JOIN `tbl_sem_linker` sl ON sl.`sem_linker_idPK` 	= tssl.`stud_sem_active`
										 LEFT JOIN `tbl_semesters`  sem ON sem.`sem_idPK` 		= sl.`sem_idFK`
										 LEFT JOIN `tbl_stud_sec`   ssec ON ssec.`sem_linker_idFK` 	= tssl.`stud_sem_active`
										 LEFT JOIN `tbl_section`   sec ON sec.`section_idPK` 	= ssec.`section_idFK`
										 WHERE tssl.`is_deleted` = 'N' AND tssl.`grade` = 'INC'
										 " . $studNoWhere
										   . $subjectWhere
										   . $semesterWhere
										   . $pageLimit);

		}
	}
?>
